Class: BinaryData

@tobydeieso/binarydata~BinaryData(data, precision)

A custom binary data type, where the binary data (binaryArray) is stored as an array of integer numbers (0's and 1's) with a bit length rounded up to the nearest 4 bit (word). The class has methods to return the binary value in other formats, including a binaryString, hexString or decimal number value.

Constructor

new BinaryData(data, precision)

Creates a new BinaryData object

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
precision number
Source:

Methods

and(data) → {string|undefined}

AND method returns a 1 in each bit position for which the corresponding bits (e.g. from the input data) of both are 1s.

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
Source:
Returns:
Type
string | undefined

get() → {binaryString|undefined}

Returns the binaryString reprsentation of the data stored within the BinaryData instance.

Source:
Returns:
Type
binaryString | undefined

getArray() → {binaryArray|undefined}

Returns a duplicated version of the internal binaryArray.

Source:
Returns:
Type
binaryArray | undefined

getConversionType() → {string}

Returns the internal detection routine used when converting input data, represented as a string. It can be one of the following 5 values:

Source:
Returns:
Type
string

getDecimal() → {decimal|undefined}

Returns the decimal value of the data stored within the BinaryData instance.

Source:
Returns:
Type
decimal | undefined

getHex(removePrefixopt) → {hexString|undefined}

Returns the hexString reprsentation of the data stored within the BinaryData instance. This can be with or without the hexadecimal string prefix of 0x.

Parameters:
Name Type Attributes Default Description
removePrefix boolean <optional>
false
Source:
Returns:
Type
hexString | undefined

getLength() → {number}

Returns the bit length of the value stored

Deprecated:
  • Since version 1.1.0
Source:
Returns:
Type
number

getPrecision() → {number}

Returns the bit length of the value stored

Source:
Returns:
Type
number

getRaw() → {decimal|hexString|binaryString|binaryArray}

Returns the raw data that was passed in when the instance was created OR when the set method was called.

Source:
Returns:
Type
decimal | hexString | binaryString | binaryArray

getString() → {binaryString|undefined}

Returns the binaryString reprsentation of the data stored within the BinaryData instance.

Source:
Returns:
Type
binaryString | undefined

leftAdd(data) → {string|undefined}

Add bit values to the left of the binary data.

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
Source:
Returns:
Type
string | undefined

leftShift(offset) → {string|undefined}

Shifts the internal binary data a specified number of bits to the left, within the precision of the BinaryData instance. Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right.

Parameters:
Name Type Description
offset number
Source:
Returns:
Type
string | undefined

not() → {string|undefined}

NOT method inverts the bits wihtin the internal binaryArray.

Source:
Returns:
Type
string | undefined

or(data) → {string|undefined}

OR method returns a 1 in each bit position for which the corresponding bits (e.g. from the input data) of either or both are 1s.

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
Source:
Returns:
Type
string | undefined

rightAdd(data) → {string|undefined}

Add bit values to the right of the binary data.

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
Source:
Returns:
Type
string | undefined

rightShift(offset) → {string|undefined}

Shifts the internal binary data a specified number of bits to the right, within the precision of the BinaryData instance. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left.

Parameters:
Name Type Description
offset number
Source:
Returns:
Type
string | undefined

set(data, precisionopt) → {boolean}

TBA

Parameters:
Name Type Attributes Description
data decimal | hexString | binaryString | binaryArray
precision number <optional>
Source:
Returns:
Type
boolean

setBit(index, value) → {string|undefined}

Manually replace the value of a single bit within the existing internal binaryArray at an index from 0 to getPrecision() - 1.

Parameters:
Name Type Description
index number
value boolean
Source:
Returns:
Type
string | undefined

xor(data) → {string|undefined}

XOR method returns a 1 in each bit position for which the corresponding bits (e.g. from the input data) of either but not both are 1s.

Parameters:
Name Type Description
data decimal | hexString | binaryString | binaryArray
Source:
Returns:
Type
string | undefined