About
Basic bits operations in the Mys programming language.
Examples
from bits import reverse
from bits import leading_ones
from bits import leading_zeros
from bits import count_ones
from bits import count_zeros
from bits import rotate_left
from bits import rotate_right
func main():
value: u32 = 0x12345678
assert reverse(value) == 0x1e6a2c48
assert leading_ones(value) == 0
assert leading_zeros(value) == 3
assert count_ones(value) == 13
assert count_zeros(value) == 19
assert rotate_left(value, 8) == 0x34567812
assert rotate_right(value, 8) == 0x78123456
API
func reverse(value: u32) -> u32:
Reverse the bit order.
func leading_ones(value: u32) -> u32:
Count number of leading bits that are one.
func leading_zeros(value: u32) -> u32:
Count number of leading bits that are zero.
func count_ones(value: u32) -> u32:
Count number of bits that are one.
func count_zeros(value: u32) -> u32:
Count number of bits that are zero.
func rotate_left(value: u32, count: u32) -> u32:
Rotate bits left count times.
func rotate_right(value: u32, count: u32) -> u32:
Rotate bits right count times.