× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Feador, Jerry wrote:
Hi All,

        I've been tasked with converting a character representation of a
binary number to it's decimal equivalent and vice versa. For example I have
a series of nine characters '001011101' and I'm suppose to get the AS/400 to
come up with 93. Or I have the decimal number 321 and I need to get to
'101000001'

        I've checked the archives and all past information deals with the
conversion of a true binary number to decimal, not this character
representation of one....

        Is it possible to just move this string into a binary field and then
to a regular numeric field?

For conversion of numbers in base 2 to decimal, try the C run-time library function "strtol()". Here's an example:


------------------------------------------------------------------
H dftactgrp(*no) bnddir('QC2LE')
D strtol          pr            10i 0 extproc('strtol')
D   nptr                          *   value options(*string)
D   endptr                        *   value
D   base                        10i 0 value
D ptr             s               *
 /free
    dsply (strtol('1': %addr(ptr): 2));
    dsply (strtol('10': %addr(ptr): 2));
    dsply (strtol('11': %addr(ptr): 2));
    dsply (strtol('100': %addr(ptr): 2));
    dsply (strtol('10010101': %addr(ptr): 2));
    *inlr = *on;
 /end-free
------------------------------------------------------------------

Cheers! Hans



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.