Class GibbonProcessor

This is the Gibbon Processor which does all the bit masking, nothing special ;)

Hierarchy

  • GibbonProcessor

Constructors

Methods

  • Change bit according to given value on data from index

    Example

    changeBit(1, 0, false); // returns 0(dec)

    // 0000 0001 data
    // 1111 1110 mask ~
    // ---------------- AND
    // 0000 0000 x1
    //
    // 0000 0000 state
    // 0000 0001 mask
    // ---------------- AND
    // 0000 0000 x2
    //
    // 0000 0000 (x1)
    // 0000 0000 (x2)
    // ---------------- OR
    // 0000 0000 result

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    • value: boolean

    Returns number

  • Set bit false on data from index

    Example

    clearBit(1, 0); // returns 0(dec)

    // 0000 0001 mask
    //
    // 0000 0001 data
    // 1111 1110 ~mask
    // ---------------- AND
    // 0000 0000 result

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    Returns number

  • Transforms a position (1..n) to byte index and inner bit position

    Example

    getByteNoAndBitPos(1); // returns { byteNo: 0, bitPos: 0}

    getByteNoAndBitPos(256); // returns { byteNo: 31, bitPos: 7}

    Returns

    • A new a BitByte instance

    Throws

    when position is <= 0

    Parameters

    • position: number = 0

      Unsigned integer value (1..n)

    Returns BitByte

  • Checks if all logical "1" bits from byte2 compare to the ones in byte1

    Example

    // 1. 0101 0010       (82 dec)
    // 2. 0100 0010 (66 dec)
    // ------------- AND
    // 0100 0010 (66 dec)
    // 66 dec === 66 dec :-)
    //

    // 1. 0010 1100 (44 dec)
    // 2. 0010 1000 (40 dec)
    // ------------- AND
    // 0010 1000 (40 dec)
    // 40 dec === 40 dec :-)

    // 1. 0000 0000 (0 dec)
    // 2. 0001 0000 (16 dec)
    // -------------- AND
    // 0000 0000 (0 dec)
    // 0 dec !== 16 dec :-(


    // 1. 0000 0000 (0 dec)
    // 2. 0010 0010 (34 dec)
    // -------------- AND
    // 0000 0000 (0 dec)
    // 0 dec !== 34 dec :-(

    Returns

    Parameters

    • param0: Object

    Returns boolean

  • Compare 2 bytes, matches when byte1 has any similar bits set compared to byte2

    Example

    // 1. 1000 1001
    // 2. 0000 1000
    // ------------- AND
    // 0000 1000 (8 dec)
    // (8 dec !== 0x0) => true

    const byte1 = 0x89; // 137 (dec)
    const byte2 = 0x8; // 8 (dec)

    hasAnyBits({byte1, byte2}); // returns true

    Returns

    Parameters

    • param0: Object

    Returns boolean

  • Check if bit is set false on index

    Example

    isFalse(13, 2); // returns false

    // 0000 1101 data
    //
    // 0000 0011 data (after data >>= index)
    // 0000 0001
    // ---------- AND
    // 0000 0001 === 0000 0000 (false)
    //

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    Returns boolean

  • Check if bit is set true on index

    Example

    isTrue(13, 2); // returns true

    // 0000 1101 data
    //
    // 0000 0011 data (after data >>= index)
    // 0000 0001
    // ---------- AND
    // 0000 0001 === 0000 0001 (true)
    //

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    Returns boolean

  • Set bit true on data from index

    Example

    setBit(0, 1); // returns 1

    // 0000 0000 data
    // 0000 0001 mask
    // ---------------- OR
    // 0000 0001 result

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    Returns number

  • Toggle (inverse) bit value on data from index

    Example

    toggleBit(1, 0); // Returns 0(dec)

    // 0000 0001 mask
    // 0000 0001 data
    // --------------- XOR
    // 0000 0000 result

    Returns

    Parameters

    • data: number = 0x0

      Unsigned integer value

    • index: number = 0

      Unsigned integer value (0..7)

    Returns number

Generated using TypeDoc