Function getBit

  • Retrieves the value of the bit at the specified position in a number.

    Returns

    1 if the bit at position k is set, otherwise 0.

    Example

    getBit(0b1010, 1); // → 1 (bit 1 is set)
    getBit(0b1010, 0); // → 0 (bit 0 is clear)

    Remarks

    • Works with any 32-bit integer representable in JavaScript.
    • Does not modify the original number.

    Parameters

    • n: number

      The number from which to retrieve the bit.

    • k: number

      Zero-based bit position to retrieve (0 = least-significant bit).

    Returns number

Generated using TypeDoc