Skip to content

$bitwise

Bit operations on integers; the language has no bitwise operators of its own.

9 natives. Read-only natives only look things up; the rest change something. Parameter types use the language's names (Types).

and

read-only
$bitwise.and(a: int, b: int) -> int

Perform a bitwise and operation.

ParameterTypeMeaning
aintFirst argument.
bintSecond argument.

Returns int: a & b

get_bit

read-only
$bitwise.get_bit(mask: int, index: int, check_index_range: bool, lower_bound: int, upper_bound: int) -> bool

Get a bit from a given bits set. If we check index range and it's out of range, it will just return false.

ParameterTypeMeaning
maskintThe bitmask.
indexintThe bit index to set.
check_index_rangeboolWhether we should check range [lower_bound, upper_bound] for the input index.
lower_boundintThe lower bound for index.
upper_boundintThe upper bound for index.

Returns bool: The value of the bit. True is 1 and false is 0.

get_set_count

read-only
$bitwise.get_set_count(mask: int) -> int

Count the number of bits set.

ParameterTypeMeaning
maskintThe bitmask.

Returns int: The number of bits set.

not

read-only
$bitwise.not(a: int) -> int

Perform a bitwise not operation.

ParameterTypeMeaning
aintArgument.

Returns int: ~a

or

read-only
$bitwise.or(a: int, b: int) -> int

Perform a bitwise or operation.

ParameterTypeMeaning
aintFirst argument.
bintSecond argument.

Returns int: a | b

set_bit

read-only
$bitwise.set_bit(mask: int, index: int, value: bool, check_index_range: bool, lower_bound: int, upper_bound: int) -> int

Set a bit in a given bits set and return the bits set. If we check index range and it's out of range, it will just return the input bits set.

ParameterTypeMeaning
maskintThe bitmask.
indexintThe bit index to set.
valueboolThe bit value to set. True is 1, and false is 0.
check_index_rangeboolWhether we should check range [lower_bound, upper_bound] for the input index.
lower_boundintThe lower bound for index.
upper_boundintThe upper bound for index.

Returns int: The result of bits set.

shift_left

read-only
$bitwise.shift_left(a: int, b: int) -> int

Perform a bitwise shift left operation.

ParameterTypeMeaning
aintFirst argument.
bintSecond argument.

Returns int: a << b

shift_right

read-only
$bitwise.shift_right(a: int, b: int) -> int

Perform an UNSIGNED bitwise shift right operation.

ParameterTypeMeaning
aintFirst argument.
bintSecond argument.

Returns int: a >> b

xor

read-only
$bitwise.xor(a: int, b: int) -> int

Perform a bitwise xor operation.

ParameterTypeMeaning
aintFirst argument.
bintSecond argument.

Returns int: a ^ b