18 lines
414 B
Fennel
18 lines
414 B
Fennel
(local byte string.char)
|
|
(fn word->byte [x]
|
|
"convert a 32 bit word into a little endian byte string"
|
|
(string.char
|
|
(-> x (band 0xff))
|
|
(-> x (rshift 8) (band 0xff))
|
|
(-> x (rshift 16) (band 0xff))
|
|
(-> x (rshift 24))))
|
|
(fn half->byte [x]
|
|
"convert a 16 bit half-word into a little endian byte string"
|
|
(string.char
|
|
(-> x (band 0xff))
|
|
(-> x (rshift 8) (band 0xff))))
|
|
|
|
{: byte
|
|
: word->byte
|
|
: half->byte}
|