Project

General

Profile

chr.p

Paul Bodale, 02/06/2026 04:54 AM

Download (906 Bytes)

 
1

    
2
USING task.HexUtils.
3

    
4
MESSAGE SESSION:CPINTERNAL.
5

    
6
DEFINE VARIABLE rawData AS RAW NO-UNDO.
7
DEFINE VARIABLE chData AS CHARACTER NO-UNDO.
8
DEFINE VARIABLE intEncoding AS INTEGER NO-UNDO.
9
DEFINE VARIABLE hexEncoding AS CHARACTER NO-UNDO.
10
DEFINE VARIABLE intCodePoint AS INTEGER NO-UNDO.
11
DEFINE VARIABLE hexCodePoint AS CHARACTER NO-UNDO.
12

    
13
chData = CHR(128, "UTF-8", "1252").
14
PUT-STRING(rawData, 1) = chData.
15
MESSAGE "# of chars:" LENGTH(chData).
16
MESSAGE "# of bytes before truncation:" LENGTH(rawData).
17

    
18
// Truncate the length to avoid adding the null terminator 
19
// This avoids an extra left shift when computing the decimal representation
20
LENGTH(rawData) = LENGTH(chData, "RAW").
21

    
22
intEncoding = HexUtils:rawToInt(rawData).
23
hexEncoding = HexUtils:rawToHex(rawData).
24

    
25
MESSAGE "# of bytes after truncation:" LENGTH(chData, "RAW").
26
MESSAGE "Hex Encoding:" hexEncoding.
27
MESSAGE "Decimal Encoding:" intEncoding.
28