Consultor Eletrônico



Kbase P125474: How to convert an INTEGER decimal number to its binary string representation?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   13/02/2010
Status: Unverified

GOAL:

ABL: How to convert an INTEGER decimal number to its binary string representation?

GOAL:

How to convert a decimal number to a binary number.

FIX:

The following procedure defines a FUNCTION that converts any non negative INTEGER number to its binary string representation:
FUNCTION getBinary RETURNS CHARACTER (INPUT ipiValue AS INTEGER) FORWARD.

MESSAGE getBinary(3) VIEW-AS ALERT-BOX.

FUNCTION getBinary RETURNS CHARACTER (INPUT ipiValue AS INTEGER):

DEFINE VARIABLE cReturn AS CHARACTER NO-UNDO.

DO WHILE ipiValue > 0:
ASSIGN
cReturn = STRING( ipiValue MOD 2 ) + cReturn
ipiValue = TRUNCATE( ipiValue / 2, 0 )
.
END.
IF cReturn = "" THEN cReturn = "0":U.
RETURN cReturn.

END FUNCTION.