Next: Linear Algebra, Previous: Arithmetic, Up: Top
Octave provides the following functions for bit twiddling.
Set or reset bit(s) n of unsigned integers in a. v = 0 resets and v = 1 sets the bits. The lowest significant bit is: n = 1
dec2bin (bitset (10, 1)) => 1011See also: bitand, bitor, bitxor, bitget, bitcmp, bitshift, bitmax.
Return the status of bit(s) n of unsigned integers in a the lowest significant bit is n = 1.
bitget (100, 8:-1:1) => 0 1 1 0 0 1 0 0See also: bitand, bitor, bitxor, bitset, bitcmp, bitshift, bitmax.
Return the k-bit complement of integers in a. If k is omitted
k = log2 (bitmax) + 1
is assumed.bitcmp(7,4) => 8 dec2bin(11) => 1011 dec2bin(bitcmp(11, 6)) => 110100See also: bitand, bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax.
Return a k bit shift of n- digit unsigned integers in a. A positive k leads to a left shift. A negative value to a right shift. If n is omitted it defaults to log2(bitmax)+1. n must be in range [1,log2(bitmax)+1] usually [1,33]
bitshift (eye (3), 1)) => 2 0 0 0 2 0 0 0 2 bitshift (10, [-2, -1, 0, 1, 2]) => 2 5 10 20 40See also: bitand, bitor, bitxor, bitset, bitget, bitcmp, bitmax.
Return the bitwise AND of nonnegative integers. x, y must be in range [0..bitmax]
See also: bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax.
Return the bitwise OR of nonnegative integers. x, y must be in range [0..bitmax]
See also: bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax.