Consultor Eletrônico



Kbase P7963: How to extract the character representation of the binary va
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   02/02/2003
Status: Unverified

GOAL:

How to extract the character representation of the binary value of an integer?

FIX:

/* The following 4GL code, using the 4GL GET-BITS function */
/* extracts the bits of a 32 bit long integer and displays */
/* its binary representation as a character string. */

DEFINE VARIABLE iInteger AS INTEGER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE cBinary AS CHARACTER NO-UNDO.

iInteger = 2147483647.
iCounter = 32.

REPEAT WHILE iCounter > 0:
cBinary = cBinary + string(GET-BITS(iInteger, iCounter, 1)).
iCounter = iCounter - 1.
END.
MESSAGE cBinary
VIEW-AS ALERT-BOX INFO BUTTONS OK.