Function setBitHigh

  • Sets (changes to 1) the bit at the specified position in a number.

    Returns

    A new number with the bit at the specified position set to 1.

    Example

    setBitHigh(0b1001, 1); // → 0b1011 (sets bit 1)
    setBitHigh(0b0111, 3); // → 0b1111 (sets bit 3)

    Remarks

    • Only the bit at the given position is affected; all other bits remain unchanged.
    • Works with any 32-bit integer representable in JavaScript.

    Parameters

    • value: number

      The original number whose bit is to be set.

    • position: number

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

    Returns number

Generated using TypeDoc