hex-string>bytes ( hex-string -- bytes ) - Factor Documentation

hex-string>bytes ( hex-string -- bytes )
Hex Strings



Vocabulary
hex-strings

Inputs
hex-string a sequence


Outputs
bytes a byte-array


Word description
Converts a sequence of hex numbers in the range [00,ff] to a sequence of bytes (integers in the range [0,255]).

Examples
USING: hex-strings prettyprint ; "cafebabe" hex-string>bytes .
B{ 202 254 186 190 }


See also
bytes>hex-string

Definition
USING: byte-arrays kernel math math.parser sequences
sequences.private ;

IN: hex-strings

: hex-string>bytes ( hex-string -- bytes )
dup length dup even? [ invalid-hex-string-length ] unless
2/ <byte-array> [
[
[ digit> ] 2dip over even?
[ [ 16 * ] [ 2/ ] [ set-nth-unsafe ] tri* ]
[ [ 2/ ] [ [ + ] change-nth-unsafe ] bi* ] if
] curry each-index
] keep ;

AltStyle によって変換されたページ (->オリジナル) /