Eightbyte
Javascript does not contain 64 bit operations....
Instead, the standard complies to a 64 bit floating point representation that gives 58 bits of precision in integers.
The functions include:
make(string)
:: Create 0x optional)and(b)
:: Logical ANDor(b)
:: Logical ORxor(b)
:: Logical XORadd(b)
:: Additionsubtract(b)
:: Subtractionmultiply(b)
:: Multiplicationdivide(b)
:: Division -> {quotient:x, remainder: y}shiftr(bits)
:: Shift rightshiftl(bits)
:: Shift leftrotl(bits)
:: Rotate leftrotr(bits)
:: Rotate rightlog2()
:: Log (base 2)hex()
:: Hex representationstring()
:: String representationwhere (b) is a 64 bit integer of format [nHigh, nLow]
TODO
- Expanded Documentation
- Malformed error test on all operations
- Expanded tests
Usage
var 'eightbyte'); var valid = 'DEADBEEF01010101')); var anded = 0x00 0x01 anded_hex = anded; var ored = 0x00 0x01 ored_hex = ored; var xored = 0x00 0x01 xored_hex = xored; var added = 0xAABBCCDD 0x0011FFEE added_hex = added; var subtracted = 0xAABBCCDD 0x0011FFEE subtracted_hex = subtracted; var mult = 0xAABBCCDD 0x0011FFEE mult_hex = mult; var divided = 0xAABBCCDD 0x0011FFEE divided_hex = divided; var shiftr = 0xAABBCCDD 0x0011FFEE shiftr_hex = shiftr; var shiftl = 0xAABBCCDD 0x0011FFEE shiftl_hex = shiftl; var rotl = 0xAABBCCDD 0x0011FFEE rotl_hex = rotl; var rotr = 0xAABBCCDD 0x0011FFEE rotr_hex = rotr; var log2 = 0xAABBCCDD 0x0011FFEE
Formating
By default, the functions return the array representation of the [32bit, 32bit]).
For hex
formatting, use:
// returns 16 character hex representation as a string
var string_hex = [0xAABBCCDD, 0xEEFF0011].hex();
// returns "AABBCCDDEEFF0011"
For string
formatting, use:
var string_value = [0xAABBCCDD, 0xEEFF0011].string();
// returns "12302652060662169617"
Testing
Install mocha
and should
using
npm install --dev
Note: npm 1.2.18
contains a bug that tries to install the development version of all devDependencies. Omit the --dev
option and it should work correctly.
Once everything is installed:
make test