๐ฅ๏ธ Bitwise#
#bs.bitwise:help
This folder contains various bitwise operators to apply to scores.
Friendly advice: decrease the volume before clicking ๐
โBinary is a very simple numbering system, but it is incredibly powerful when used correctly.โ
โAlan Turing
๐ง Functions#
You can find below all the function available in this module.
logical AND#
#bs.bitwise:and
Computes the bitwise conjunction of the two input numbers
- Inputs
- (score)
$bitwise.and.a bs.in
The first operand \(a\)
- (score)
$bitwise.and.b bs.in
The second operand \(b\)
Negative input
If one of the inputs is negative, the operation will be done between the first operand and the twoโs complement of the second
- (score)
- Outputs
- (score)
$bitwise.and bs.out
The result of the operation = \(a \times b\)
- (score)
- Example
Calculate and display \(-9 \times 57\)
# Once scoreboard players set $bitwise.and.a bs.in -9 scoreboard players set $bitwise.and.b bs.in 57 function #bs.bitwise:and tellraw @a [{"text":"-9 & 57 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.and", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet, Aksiome
logical OR#
#bs.bitwise:or
Computes the bit to bit disjunction of the two input numbers
- Inputs
- (score)
$bitwise.or.a bs.in
The first operand \(a\)
- (score)
$bitwise.or.b bs.in
The second operand \(b\)
Negative input
If one of the inputs is negative, the operation will be done between the first operand and the twoโs complement of the second
- (score)
- Outputs
- (score)
$bitwise.or bs.out
The result of the operation = \(a + b\)
- (score)
- Example
Calculate and display \(-9 + 57\).
# Once scoreboard players set $bitwise.or.a bs.in -9 scoreboard players set $bitwise.or.b bs.in 57 function #bs.bitwise:or tellraw @a [{"text":"-9 | 57 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.or", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet, Aksiome
logical XOR#
#bs.bitwise:xor
Computes the exclusive bit by bit disjunction of the two input numbers
- Inputs
- (score)
$bitwise.xor.a bs.in
The first operand \(a\)
- (score)
$bitwise.xor.b bs.in
The second operand \(b\)
Negative input
If one of the inputs is negative, the operation will be done between the first operand and the twoโs complement of the second
- (score)
- Outputs
- (score)
$bitwise.xor bs.out
The result of the operation = \(a \oplus b\)
- (score)
- Example
Calculate and display \(-9 \oplus 57\).
# Once scoreboard players set $bitwise.xor.a bs.in -9 scoreboard players set $bitwise.xor.b bs.in 57 function #bs.bitwise:xor tellraw @a [{"text":"-9 ^ 57 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.xor", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet, Aksiome
logical NOT#
#bs.bitwise:not
Computes the bit by bit negation of the input
- Inputs
- (score)
$bitwise.not.value bs.in
The number you want to negate
- (score)
- Outputs
- (score)
$bitwise.not bs.out
The result of the not operation
- (score)
- Example
Calculate and display \(~452\)
# Once scoreboard players set $bitwise.not.value bs.in 452 function #bs.bitwise:not tellraw @a [{"text":"~452 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.not", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet
Bit count#
#bs.bitwise:bit_count
Calculates the number of bits needed to store the input
- Inputs
- (score)
$bitwise.bit_count.value bs.in
The number you want to know the number of bits
- (score)
- Outputs
- (score)
$bitwise.bit_count bs.out
The number of bits needed to store the input
Negative input
If the input is negative, returns the number of bits needed to store the absolute value of the number
- (score)
- Example
Calculate and display the number of bits of 12
# Once scoreboard players set $bitwise.bit_count.value bs.in 12 function #bs.bitwise:bit_count tellraw @a [{"text": "Number of bits of 12 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.bit_count", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet
Complement to 2#
#bs.bitwise:two_complement
Computes the twoโs complement of the input
- Inputs
- (score)
$bitwise.two_complement.value bs.in
The number you want to compute the twoโs complement
- (score)
- Outputs
- (score)
$bitwise.two_complement bs.out
The twoโs complement of the input
- (score)
- Example
Calculate and display the twoโs complement of 12
# Once scoreboard players set $bitwise.two_complement.value bs.in 12 function #bs.bitwise:two_complement tellraw @a [{"text": "Two's complement of 12 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.two_complement", "objective": "bs.out"}, "color": "gold"}]
Credits: theogiraudet
Most significant bit#
#bs.bitwise:msb
Get the value of the most significant bit of the input
- Inputs
- (score)
$bitwise.msb.value bs.in
The number you want to compute the msb
- (score)
- Outputs
- (score)
$bitwise.msb bs.out
The value of the msb of the input
- (score)
- Example
Calculate and display the value of the most significant bit of 12
# Once scoreboard players set $bitwise.msb.value bs.in 12 function #bs.bitwise:msb tellraw @a [{"text": "MSB of 12 = ", "color": "dark_gray"},{"score":{"name":"$bitwise.msb", "objective": "bs.out"}, "color": "gold"}]
Credits: Aksiome
๐ฌ Did it help you?
Feel free to leave your questions and feedbacks below!