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



Hi Leif

You can use TESTB to test each bit in turn and update a return string with
the result.  The following HEX2BIN procedure should do what you want:

     H DFTACTGRP(*NO)

     D Hex2Bin         pr             8a
     D  iHex                          1a   Value

     D wResult         s              8a

     C                   Eval      wResult=Hex2Bin('A')
     C     wResult       Dsply

     C                   Eval      wResult=Hex2Bin('B')
     C     wResult       Dsply

     C                   Eval      wResult=Hex2Bin('C')
     C     wResult       Dsply

     C                   Eval      wResult=Hex2Bin('1')
     C     wResult       Dsply

     C                   Eval      wResult=Hex2Bin('2')
     C     wResult       Dsply

     C                   Eval      wResult=Hex2Bin('3')
     C     wResult       Dsply

     C                   Eval      *InLr = *On

     p Hex2Bin         b

     D Hex2Bin         pi             8a
     D  iHex                          1a   Value

     D oBinary         s              8a
     D Set             s              1a   Inz('1')

     D IndPtr          s               *   Inz(%Addr(*In))
     D IndAra          Ds                  Based(IndPtr)
     D  Bit                   91     91

      * Reset the binary string to be returned...

     C                   Eval      oBinary = '00000000'

      * Test each bit in turn and move the result to the appropriate
      * character of the output field...

     C                   TestB     '0'           iHex                     91
     C                   Eval      %Subst(oBinary:1:1) = *In91

     C                   TestB     '1'           iHex                     91
     C                   Eval      %Subst(oBinary:2:1) = *In91

     C                   TestB     '2'           iHex                     91
     C                   Eval      %Subst(oBinary:3:1) = *In91

     C                   TestB     '3'           iHex                     91
     C                   Eval      %Subst(oBinary:4:1) = *In91

     C                   TestB     '4'           iHex                     91
     C                   Eval      %Subst(oBinary:5:1) = *In91

     C                   TestB     '5'           iHex                     91
     C                   Eval      %Subst(oBinary:6:1) = *In91

     C                   TestB     '6'           iHex                     91
     C                   Eval      %Subst(oBinary:7:1) = *In91

     C                   TestB     '7'           iHex                     91
     C                   Eval      %Subst(oBinary:8:1) = *In91

     C                   Return    oBinary

     p Hex2Bin         e

Hope it helps

All the best

Jonathan
www.astradyne-uk.com

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Leif Guldbrand
Sent: 08 April 2006 21:40
To: rpg400-l@xxxxxxxxxxxx
Subject: Convert from Hex to Binary....

Hi,

I receive some data from a industrial I/O box (Beckhoff BK9000) thru
Modbus protocol over TCP/IP in my socket client program (thanks Scott :)

One byte is the status of 8 input registres and is received in Hex from
x'00' to  x'FF'.

I need to change this value into a binary string.

An example.... I receive the value x'80' which should be converted to
'1000 0000' and end up in a data structure with 8 fields.

I've Googled around, but could only find the thing I want, doing it with
REXX and the function   X2B('C3')        ->  '11000011'

I want to do this inside my program.... any help out there ???

Best regards,
Leif



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.