|
>> How do you convert a binary value to decimal in RPG400
If you have to convert 1 or 3 byte binaries then you have some "fiddling"
to do - e-mail me directly if you need that information. If you just have
2 and 4 byte bin to convert then you do it as below. Note that no
"conversion" is really needed - just define the field the right way and use
it directly wherever you need it.
In RPG/400 (i.e. RPG III) you code it this way but note that you cannot get
the full potential range of the binary as RPG III's B data type limits the
number of digits to 9 for a 4 byte binary and 4 for a two byte. This may
be enough for you though.
I DS
I* Change field lengths to 2 chars for two byte bin
I B 1 40BIN4
I P 5 80PKD9
C MOVE BIN4 PKD9
In RPG IV you would code it this way and get the full 5/10 digits:
* Replace 10I with 5I for two byte binary
D Bin4Value S 10I 0
D Dec10Value S 10P 0
C Eval Dec10Value = Bin4Value
* OR
C Move Bin4Value Dec10Value
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.