Logo

Programming-Idioms

History of Idiom 176 > diff from v5 to v6

Edit summary for version 6 by 1.7.4:
New JS implementation by user [1.7.4]

Version 5

2018-12-30, 12:39:22

Version 6

2019-01-24, 13:35:04

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
Code
const base = 16
let a = s
  .replace(/../, '$&_') // hi perl
  .slice (0, -1) // take off the last one
  .split ('_')
  .map (
    ([x, y]) => parseInt (x, 16) * 16 + parseInt (y, 16)
  )