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