# 🖥️ Bitwise#

`#bs.bitwise:help`

A collection of various bitwise operations, providing versatile tools for manipulating binary data.

“Binary is a very simple numbering system, but it is incredibly powerful when used correctly.”

—Alan Turing

## 🔧 Functions#

You can find below all functions available in this module.

### Bit count#

- #bs.bitwise:bit_count
Get the number of ones in the binary representation of a number.

- Inputs:
**Score**: Number to get the bit_count of.`$bitwise.bit_count.n bs.in`

- Outputs:
**Return | Score**: Number of positive bits needed to represent the number.`$bitwise.bit_count bs.out`

*Compute and display how much positive bits 12 has:*

```
# Once
scoreboard players set $bitwise.bit_count.n bs.in 12
function #bs.bitwise:bit_count
# See the result
tellraw @a [{"text":"Number of bits for 12 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.bit_count","objective":"bs.out"}}]
```

Credits: Aksiome

### Bit length#

- #bs.bitwise:bit_length
Get the number of bits necessary to represent a number.

- Inputs:
**Score**: Number to get the bit_length of.`$bitwise.bit_length.n bs.in`

- Outputs:
**Return | Score**: Number of bits needed to represent the number.`$bitwise.bit_length bs.out`

*Compute and display how much bits 12 has:*

```
# Once
scoreboard players set $bitwise.bit_length.n bs.in 12
function #bs.bitwise:bit_length
# See the result
tellraw @a [{"text":"Number of bits for 12 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.bit_length","objective":"bs.out"}}]
```

Credits: Aksiome, theogiraudet

### Complement to 2#

- #bs.bitwise:two_complement
Compute the two’s complement of a number.

- Inputs:
**Score**: Number to compute the two’s complement of.`$bitwise.two_complement.n bs.in`

- Outputs:
**Return | Score**: The two’s complement of the number.`$bitwise.two_complement bs.out`

*Compute and display the two’s complement of -12:*

```
# Once
scoreboard players set $bitwise.two_complement.n bs.in -12
function #bs.bitwise:two_complement
# See the result
tellraw @a [{"text":"Two's complement of -12 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.two_complement","objective":"bs.out"}}]
```

Credits: Aksiome, theogiraudet

### Logical operators#

- #bs.bitwise:and
Compute the bitwise conjunction of two numbers.

- Inputs:
**Score**: First operand \(=a\).`$bitwise.and.a bs.in`

**Score**: Second operand \(=b\).`$bitwise.and.b bs.in`

- Outputs:
**Return | Score**: Result of the operation \(=a \land b\).`$bitwise.and bs.out`

*Compute and display \(-9 \land 57\):*

```
# Once
scoreboard players set $bitwise.and.a bs.in -9
scoreboard players set $bitwise.and.b bs.in 57
function #bs.bitwise:and
# See the result
tellraw @a [{"text":"-9 & 57 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.and","objective":"bs.out"}}]
```

- #bs.bitwise:or
Compute the bitwise disjunction of two numbers.

- Inputs:
**Score**: First operand \(=a\).`$bitwise.or.a bs.in`

**Score**: Second operand \(=b\).`$bitwise.or.b bs.in`

- Outputs:
**Return | Score**: Result of the operation \(=a \lor b\).`$bitwise.or bs.out`

*Compute and display \(-9 \lor 57\):*

```
# Once
scoreboard players set $bitwise.or.a bs.in -9
scoreboard players set $bitwise.or.b bs.in 57
function #bs.bitwise:or
# See the result
tellraw @a [{"text":"-9 | 57 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.or","objective":"bs.out"}}]
```

- #bs.bitwise:xor
Compute the exclusive bitwise disjunction of two numbers.

- Inputs:
**Score**: First operand \(=a\).`$bitwise.xor.a bs.in`

**Score**: Second operand \(=b\).`$bitwise.xor.b bs.in`

- Outputs:
**Return | Score**: Result of the operation \(=a \oplus b\).`$bitwise.xor bs.out`

*Compute 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
# See the result
tellraw @a [{"text":"-9 ^ 57 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.xor","objective":"bs.out"}}]
```

- #bs.bitwise:not
Compute the bitwise negation of a number.

- Inputs:
**Score**: Number to negate.`$bitwise.not.n bs.in`

- Outputs:
**Return | Score**: Result of the not operation.`$bitwise.not bs.out`

*Compute and display \(\lnot 452\):*

```
# Once
scoreboard players set $bitwise.not.n bs.in 452
function #bs.bitwise:not
# See the result
tellraw @a [{"text":"~452 = ","color":"#e0c7ff"},{"score":{"name":"$bitwise.not","objective":"bs.out"}}]
```

Credits: Aksiome, theogiraudet

**💬 Did it help you?**

Feel free to leave your questions and feedbacks below!