Logo

Programming-Idioms

History of Idiom 176 > diff from v4 to v5

Edit summary for version 5 by programming-idioms.org:
[Pascal] No begin/end needed

Version 4

2018-12-28, 22:15:57

Version 5

2018-12-30, 12:39:22

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