|
Too bad _ltoa and _itoa are V5R1 additions because the don't seem to compile under V4R5M0. :( Bob Cozzi Cozzi Consulting www.rpgiv.com -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Steve Richter Sent: Monday, June 09, 2003 1:21 PM To: RPG programming on the AS400 / iSeries Subject: RE: Binary Characters to Decimal Hi Bob, what about itoa? where the 3rd parm is the radix. when radix = 2 the output string contains a binary string. int nVlu ; char sResult[256] ; char* pResult ; nVlu = 25 ; pResult = itoa( nVlu, sResult, 2 ) ; -Steve Richter -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Bob cozzi Sent: Monday, June 09, 2003 12:12 PM To: 'RPG programming on the AS400 / iSeries' Subject: RE: Binary Characters to Decimal Jerry, As Hans pointed out strtol (or strtoll for larger numbers) converts from binary notation 101101 to decimal, but did you ever find a way to go backwards? I have an old RPGIII grunt method technique that I've been using for 10 years, but I'd rather find a simpler method. Just wondering. Bob Cozzi Cozzi Consulting www.rpgiv.com -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Hans Boldt Sent: Friday, June 06, 2003 8:07 AM To: rpg400-l@xxxxxxxxxxxx Subject: Re: Binary Characters to Decimal 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 _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.