Kbase P125416: ABL: How to convert an INTEGER number to its binary string representation?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/02/2010 |
|
Status: Verified
GOAL:
How to convert a decimal number to a binary number.
GOAL:
ABL: How to convert an INTEGER number to its binary string representation?
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.