Kbase 17886: How to convert DECIMAL values to HEXADECIMAL with a FUNCTION
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/12/1998 |
|
How to convert DECIMAL values to HEXADECIMAL with a FUNCTION
Here is an example of a FUNCTION which converts a DECIMAL value to an
HEXADECIMAL one. The sample code contains the function and some 4GL
code to show its usage. It can be customized to suit special needs.
Notice that there is no limitation in the range, that is it can
convert any integer value to its hexadecimal representation (maybe you
need to change the FORMAT when displaying the values).
Functions are available on Progress versions 8.2 and later. For
previous versions you may want to convert the code to an internal or
external procedure, include file, or whatever suits best your needs.
jsa
1 May 98
The procedure:
/* hex.p */
FUNCTION hex RETURNS CHARACTER (INPUT asc-value AS INTEGER).
DEF VAR j AS INT NO-UNDO.
DEF VAR h AS CHAR NO-UNDO.
DO WHILE TRUE:
j = asc-value MODULO 16.
h = (IF j < 10 THEN STRING(j) ELSE CHR(ASC("A") + j - 10)) + h.
IF asc-value < 16 THEN LEAVE.
asc-value = (asc-value - j) / 16.
END.
RETURN ("0x" + h).
END FUNCTION.
DEF VAR i AS INT NO-UNDO.
DO i = 1 TO 255 WITH DOWN:
DISP i hex(i).
END.
Progress Software Technical Support Note # 17886