Decimal to "Character" Binary Conversion

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Decimal to "Character" Binary Conversion

Q: Is there a way to convert decimal data to binary in "character" form using RPG or CL on an AS/400? 3 illustrates the type of conversion I need. The pseudo-binary will be used to test all possible permutations in another array.

Q: Is there a way to convert decimal data to binary in "character" form using RPG or CL on an AS/400? Figure 3 illustrates the type of conversion I need. The pseudo-binary will be used to test all possible permutations in another array.

A: Yes, there is an easy way to perform this conversion. The program in 4 will do the job.

A: Yes, there is an easy way to perform this conversion. The program in Figure 4 will do the job.

Just pass in a decimal value between 0 and 255 that you want to convert and this program will pass back the binary representation in an eight-byte character field.


Decimal to "Character" Binary Conversion

Figure 3 Conversion Specification

 1 ---> "00000001" 2 ---> "00000010" character variables 255 ---> "11111111" 
Decimal to "Character" Binary Conversion

Figure 4 Decimal to "Character" Binary Conversion

 *=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/XRK001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 I DS I B 1 20BIN I 2 2 CHRBIN C *ENTRY PLIST C PARM DECVAL 30 C PARM BINREP 8 * C Z-ADDDECVAL BIN C TESTB'0' CHRBIN 90 C TESTB'1' CHRBIN 91 C TESTB'2' CHRBIN 92 C TESTB'3' CHRBIN 93 C TESTB'4' CHRBIN 94 C TESTB'5' CHRBIN 95 C TESTB'6' CHRBIN 96 C TESTB'7' CHRBIN 97 C MOVEA*IN,90 BINREP * C MOVE *ON *INLR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
BLOG COMMENTS POWERED BY DISQUS