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).
-
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.
var bite = require('bite');
var buffer = new Buffer([0xFF, 0xFF]);
var value = bite.decodeWord(buffer, true); // = -1
var word = bite.encodeWord(new Buffer(2), value); // = <Buffer ff ff>