DIGIT() returns the upper or lower value of a packed byte at a specified position in the record.
Use DIGIT() when you require access to individual half-bytes in applications such as Unisys and NCR, which use half-byte-aligned packed fields.
DIGIT(N,1|2)
The DIGIT() function separates individual halves of a byte. The first parameter allows you to specify a byte position in the record and the second parameter allows you to specify 1 to return the upper half of the byte or 2 to return the lower half of the byte. In both instances, the half-byte value is returned as a digit between 0 and 15.
A packed field with the value 123.45 (00 12 34 5C), containing two decimals and starting in byte position 10, appears in the data record in the following format:
|
Byte 10 |
Byte 11 |
Byte 12 |
Byte 13 |
UPPER (1) |
0 |
1 |
3 |
5 |
LOWER (2) |
0 |
2 |
4 |
C |
To find what digit appears in the 12th position in the upper half of the byte, use:
DIGIT(12,1) = 3
To find what digit appears in the 12th position in the lower half of the byte, use:
DIGIT(12,2) = 4
For more information on working with UNISYS data, see Unisys.