bite
Lightweight library for word decoding in pure javascript. Contains methods for decoding/encoding bytestring words to/from numbers (signed and unsigned, big and little endian).
API
-
decodeWord(< Buffer >buffer, [< bool >signed], [< bool >bigEndian]) - (void)
Decodes a word contained inbuffer
, i.e. all ofbuffer
is treated as one word. Treats the word as signed ifsigned
is set totrue
(false
is default), and big endian ifbigEndian
is set totrue
(false
is default). -
encodeWord(< Buffer >buffer, < number >value, [< bool >signed], [< bool >bigEndian]) - (buffer)
Encodes a numbervalue
into a bytestring word of the same length asbuffer
, and stores the result inbuffer
. Will create the word as signed ifsigned
is set totrue
(false
is default), and big endian ifbigEndian
is set totrue
(false
is default). The buffer provided is returned for convenience.
Example
var bite = ; var buffer = 0xFF 0xFF;var value = bite; // = -1var word = bite; // = <Buffer ff ff>