Skip to content

Commit

Permalink
Adding bitmask explainer to docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectricKeet authored and tildearrow committed Oct 17, 2023
1 parent e72477d commit 7970b36
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/1-intro/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

**bitbang**: to achieve PCM sound by sending a rapid stream of volume commands to a non-PCM channel.

**bitmask**: a set of bits which represent individual single-bit toggles or groups representing small numbers. these are explained fully in the [hexadecimal primer](hex.md).

**BRR**: a lossy sample format used by the SNES. it has a fixed compression ratio; groups of 32 bytes (16 samples) are encoded in 9 bytes each.
- usually stored in .brr files.

Expand Down
30 changes: 30 additions & 0 deletions doc/1-intro/hex.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ now for decimal number `69420`:
= 10F2C
```

## bitmask

a bitmask is a value that actually represents a set of individual binary bits to be toggled, some of which may be grouped to form small binary numbers. these are used by adding up the value of each bit and converting the result to hex. in macros, these are shown in decimal.

bit | binary | decimal
:-----|:-----------:|--------:
bit 7 | `1000 0000` | 128
bit 6 | `0100 0000` | 64
bit 5 | `0010 0000` | 32
bit 4 | `0001 0000` | 16
bit 3 | `0000 1000` | 8
bit 2 | `0000 0100` | 4
bit 1 | `0000 0010` | 2
bit 0 | `0000 0001` | 1

for example, to turn bits 7 and 5 on, and put `110` (decimal 6) in bits 1 to 3:

```
bit 7 = `1... ....` = 128
bit 6 = `.0.. ....` = 0
bit 5 = `..1. ....` = 32
bit 4 = `...0 ....` = 0
bit 3 = `.... 1...` = 8
bit 2 = `.... .1..` = 4
bit 1 = `.... ..0.` = 0
bit 0 = `.... ...0` = 0
``````
added together, the resulting binary is `1010 1100`, which converts to hex as `AC` and to decimal as 172.
## hex to decimal table
hex | `0` | `1` | `2` | `3` | `4` | `5` | `6` | `7` | `8` | `9` | `A` | `B` | `C` | `D` | `E` | `F`
Expand Down

0 comments on commit 7970b36

Please sign in to comment.