Skip to content

bitget

Read a specific bit of an integer value.

B = bitget(A, bit)
B = bitget(A, bit, type)

Returns the value (0 or 1) of the bit at position bit in A. bit is 1-based — 1 selects the least significant bit. The optional type string controls how A is interpreted as an integer (defaults to int64). A and bit are broadcast to a common shape.

bitget(10, 2) % 1 (10 = 1010, bit 1 is 1)
bitget(10, 1) % 0
bitget(255, 1:8) % [1 1 1 1 1 1 1 1]
  • bitset — Set or clear a specific bit of an integer value.
  • bitshift — Shift the bits of an integer left or right.