Logo

Programming-Idioms

History of Idiom 176 > diff from v3 to v4

Edit summary for version 4 by Bart:
New Pascal implementation by user [Bart]

Version 3

2018-12-16, 13:57:33

Version 4

2018-12-28, 22:15:57

Idiom #176 Hex string to byte array

From hex string s of 2n digits, build the equivalent array a of n bytes.
Each pair of hexadecimal characters (16 possible values per digit) is decoded into one byte (256 possible values).

Idiom #176 Hex string to byte array

From hex string s of 2n digits, build the equivalent array a of n bytes.
Each pair of hexadecimal characters (16 possible values per digit) is decoded into one byte (256 possible values).

Extra Keywords
hexa
Extra Keywords
hexa
Imports
sysutils
Code
begin
  for i := 0 to length(s) div 2 - 1 do
    a[i] := StrToInt('$'+Copy(s,2*(i)+1,2));
end.
Comments bubble
Strings are 1-based in Pascal.
The '$' prefix denotes hexadecimal numbers (like 0x in C)