HEXBYT: Converting a Decimal Integer to a Character

How to:

The HEXBYT function obtains the ASCII, EBCDIC, or Unicode character equivalent of a decimal integer, depending on your configuration and operating environment. It returns a single alphanumeric character in the ASCII, EBCDIC, or Unicode character set. You can use this function to produce characters that are not on your keyboard, similar to the CTRAN function.

In Unicode configurations, this function uses values in the range:

The display of special characters depends on your software and hardware; not all special characters may appear. For printable ASCII and EBCDIC characters and their integer equivalents see the Character Chart for ASCII and EBCDIC.


Top of page

x
Syntax: How to Convert a Decimal Integer to a Character
HEXBYT(decimal_value, output)

where:

decimal_value
Integer

Is the decimal integer to be converted to a single character. In non-Unicode environments, a value greater than 255 is treated as the remainder of decimal_value divided by 256.

output
Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.



Example: Converting a Decimal Integer to a Character

HEXBYT converts LAST_INIT_CODE to its character equivalent and stores the result in LAST_INIT:

TABLE FILE EMPLOYEE
PRINT LAST_NAME AND
COMPUTE LAST_INIT_CODE/I3 = BYTVAL(LAST_NAME, 'I3');
COMPUTE LAST_INIT/A1 = HEXBYT(LAST_INIT_CODE, LAST_INIT);
WHERE DEPARTMENT EQ 'MIS';
END

The output for an ASCII platform is:

LAST_NAME LAST_INIT_CODE LAST_INIT 
--------- -------------- --------- 
SMITH                 83 S 
JONES                 74 J 
MCCOY                 77 M 
BLACKWOOD             66 B 
GREENSPAN             71 G 
CROSS                 67 C

The output for an EBCDIC platform is:

LAST_NAME LAST_INIT_CODE LAST_INIT 
--------- -------------- --------- 
SMITH                226 S 
JONES                209 J 
MCCOY                212 M 
BLACKWOOD            194 B 
GREENSPAN            199 G 
CROSS                195 C


Example: Inserting Braces for Mainframe

HEXBYT converts the decimal integer 192 to its EBCDIC character equivalent, which is a left brace; and the decimal integer 208 to its character equivalent, which is a right brace. If the value of CURR_SAL is less than 12000, the value of LAST_NAME is enclosed in braces.

DEFINE FILE EMPLOYEE
BRACE/A17 = HEXBYT(192, 'A1') | LAST_NAME | HEXBYT(208, 'A1');
BNAME/A17 = IF CURR_SAL LT 12000 THEN BRACE
ELSE LAST_NAME;
END
TABLE FILE EMPLOYEE
PRINT BNAME CURR_SAL BY EMP_ID
END

The output is:

EMP_ID     BNAME                          CURR_SAL 
------     -----                          -------- 
071382660  {STEVENS        }            $11,000.00 
112847612  SMITH                        $13,200.00 
117593129  JONES                        $18,480.00 
119265415  {SMITH          }             $9,500.00 
119329144  BANNING                      $29,700.00 
123764317  IRVING                       $26,862.00 
126724188  ROMANS                       $21,120.00 
219984371  MCCOY                        $18,480.00 
326179357  BLACKWOOD                    $21,780.00 
451123478  MCKNIGHT                     $16,100.00 
543729165  {GREENSPAN      }             $9,000.00 
818692173  CROSS                        $27,062.00

Information Builders