BitString
a very simple bit operation module, this module is base created for dns header decode/encode.
npm install node-bitstring
Example
let BitString = ; // let bitOpt = new BitString(Buffer.alloc(2)); create a bit string with 32 bits let bitOpt = 32;//BitString {buffer: <Buffer 00 00 00 00>,binaryString: '00000000000000000000000000000000' }//create a bit string with 32 bits//should be a number which can divide by 8//if not it will auto fill bitOpt; //"11111100000000000000000000000000"bitOpt; //"11000000000000000000000000000000"bitOpt; //"00011100000000000000000000000000"// The number will conversion to the string if the number start will 0 it will be ignoredbitOpt; //"0001110000"bitOpt; //"00011100000000000000000000000000"; if length out-of-bounds, the excess part will be ignored;bitOpt; //false; if index out-of-bounds, the excess part will be ignored; bitOptbuffer; // <Buffer 1c 00 00 00>bitOptbinaryString; // "00011100000000000000000000000000"
Instance Methods
BitString(data)
: data
Can be either a number or buffer;
BitString#get(index,length)
: Returns a binary string;
BitString#set(index,value)
: Set the value of the bits. index
start position value
should be number string "0" will be set to 0, other is 1. if value out-of-bounds, the excess part will be ignored;
BitString#bufferToBinaryString(buf)
: Returns a binary string;
bitOpt; //"10101010101110111100110011011101"
BitString#binaryStringToHexString(binaryString)
: Returns a Hex string;
bitOpt# // "AABBCCDD"
Properties
BitString#buffer
: The contents of the BitString.
BitString#binaryString
: The contents of the BitString.
License
MIT