Bitwise Functions¶
Binary operations and conversions.
Bitwise Operations¶
bitwise_and(a, b)¶
Bitwise AND.
bitwise_or(a, b)¶
Bitwise OR.
bitwise_xor(a, b)¶
Bitwise XOR.
bitwise_not(a)¶
Bitwise NOT.
Shifting¶
shift_left(value, bits)¶
Left shift (multiply by 2^bits).
print shift_left(5, 1); // 10 (5 * 2)
print shift_left(5, 2); // 20 (5 * 4)
print shift_left(5, 3); // 40 (5 * 8)
shift_right(value, bits)¶
Right shift (divide by 2^bits).
Utilities¶
count_bits(number)¶
Count set bits (1s).
print count_bits(7); // 3 (binary: 111)
print count_bits(15); // 4 (binary: 1111)
print count_bits(8); // 1 (binary: 1000)
to_binary(number)¶
Convert to binary string.
from_binary(string)¶
Convert binary string to number.
to_hex(number)¶
Convert to hexadecimal string.
from_hex(string)¶
Convert hex string to number.