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

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: