× 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.



On 9/9/2019 8:59 AM, David Gibbs via RPG400-L wrote:
On Mon, Sep 9, 2019 at 7:47 AM David Gibbs <david@xxxxxxxxxxxx> wrote:
Does anyone have a routine handy (or know of an API) that will convert
hex characters to decimal or integer?

For example: If I have the character value 'BC614E' I would get
12345678 returned.
I think I solved my own problem.

There is an api to do what I want ... I just misunderstood what it does.


David, glad you found your answer.  I did something a little more generic for an earlier question.  The C functions strtol and itoa convert to between integer and character using any radix.  More than you need, but it's available for anything.  Just in case you need to do that octal conversion you've been eyeing...


On 7/29/2019 4:10 AM, Chamara Withanachchi wrote:

Hi,

I have a Binary representation of Hex value 003D as
00000000000000000000000000111101 this is in a 32 length Character field, I
want to represent this in 4 Character field using bit operations. can
someone guide me how to do this in free format.


Chamara, this might be overkill but it would also provide you a lot of flexibility in the future.  I've got a short program below that uses the C libraries to convert your data to and from an integer, using a radix (or base).  First, I use strtol to convert your binary string to an integer.  For this, I use radix = 2. Then, I use itoa to convert that integer to a hexadecimal string using base 16.

This may not perform as quick as a roll-your-own method, but it has the advantages of not having to write and debug your own code, and also it will familiarize your with the conversions.  I hope this helps.


       ctl-opt actgrp(*new) option(*srcstmt:*nodebugio);

       dcl-pr strtol int(10) extproc('strtol');
         iString pointer value options(*string);
         oBuf pointer value;
         iRadix int(10) value;
       end-pr;
       dcl-s pdummy pointer;

       dcl-pr itoa extproc('__itoa');
         iNum int(10) value;
         oBuf pointer value;
         iRadix int(10) value;
       end-pr;

       dcl-s buffer char(20);
       dcl-s value int(10);

       value = strtol( '00000000000000000000000000111101': %addr(pdummy): 2);
       dsply value;  // Shows 61

       itoa( value: %addr(buffer): 16);
       dsply buffer;  // Shows 3d

       *inlr = *on;


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.