Number Systems and Binary Concepts
Digital systems such as MIDI, computers, and microcontrollers represent all data using numbers. To understand how bytes, bits, MSB/LSB, and signed values work, it is important to understand the number systems used to represent those numbers.
Decimal Number System (Base 10)
The decimal system is the one humans use every day. Uses digits: 0–9 Each position represents a power of 10 Example:
345 = 3×100 + 4×10 + 5×1Decimal is convenient for humans, but inefficient for electronic systems.
Binary Number System (Base 2)
Computers and digital protocols use binary, which has only two digits:
- 0 (off)
- 1 (on)
Each position represents a power of 2.
Example:
1011 (binary)
= 1×8 + 0×4 + 1×2 + 1×1
= 11 (decimal)Binary maps directly to electronic circuits.
Bits and Bytes
- Bit: a single binary digit (0 or 1)
- Byte: 8 bits grouped together
Example byte:
01100001A byte can represent values from:
- 0 to 255 (unsigned)
MIDI uses 7-bit data values inside 8-bit bytes.
Hexadecimal Number System (Base 16)
Hexadecimal (hex) is a compact way to write binary numbers. Digits used:
0–9, A–FWhere:
A = 10
B = 11
C = 12
D = 13
E = 14
F = 15Each hex digit represents 4 binary bits.
Binary ↔ Hex Relationship
Example:
Binary: 10101100
Grouped: 1010 1100
Hex: A CSo:
10101100 (binary) = 0xAC (hex)This is why hex is widely used in MIDI documentation.
Decimal, Hex, and Binary Side by Side
| Decimal | Hex | Binary |
|---|---|---|
| 0 | 0x00 | 00000000 |
| 10 | 0x0A | 00001010 |
| 64 | 0x40 | 01000000 |
| 127 | 0x7F | 01111111 |
| 128 | 0x80 | 10000000 |
| 255 | 0xFF | 11111111 |
Why MIDI Uses 7-bit Values
MIDI data bytes must be in the range:
00000000 – 01111111This ensures the highest bit is always 0, distinguishing data bytes from status bytes.
Most Significant Bit (MSB) and Least Significant Bit (LSB)
In a binary number:
- MSB is the leftmost bit
- LSB is the rightmost bit
Example:
Binary: 10110010
↑ ↑
MSB LSBThe MSB represents the largest value.
MSB and LSB in Multi-Byte Values
For values larger than 7 bits (like 14-bit MIDI values), data is split:
14-bit value:
[ MSB (7 bits) ][ LSB (7 bits) ]Example:
Value = 8192
MSB = 64
LSB = 0What Is a Nibble?
A nibble is 4 bits.
Examples:
- One hex digit = one nibble
- One byte = two nibbles
Byte: 10101100
Nibbles: 1010 1100Nibble terminology is often used when discussing hex and bit masking.
Signed vs Unsigned Numbers
Unsigned Numbers Unsigned numbers represent only positive values. Example (8-bit):
0 – 255Used for:
- MIDI notes
- velocities
- CC values
Signed Numbers
Signed numbers represent both positive and negative values.
This is necessary for:
- pitch bend direction
- offsets
- relative movement
Sign Bit
In signed representations:
the MSB is often used as the sign bit
- 0 → positive
- 1 → negative
But this alone is not enough — this is where two’s complement comes in.
Two’s Complement Representation
Two’s complement is the standard way computers represent signed numbers. Key Properties
For an 8-bit number:
- Range: -128 to +127
- Zero is represented normally
- Negative numbers wrap around
Positive Example:
+5
Binary: 00000101Negative Example;
To represent -5:
- Write 5 in binary
- Invert all bits
- Add 1
5 = 00000101
~5 = 11111010
+1 = 11111011 → -5Why Two’s Complement Is Used
- Only one zero exists
- Arithmetic works naturally
- Hardware is simpler
- This is why nearly all modern systems use it.
Pitch Bend and Signed Values
Pitch bend uses a signed 14-bit value, but is transmitted as unsigned bytes.
- Center value: 8192
- Below center → bend down
- Above center → bend up
The receiving device interprets this as signed internally.
Summary
Decimal, binary, and hexadecimal are different ways to represent the same numbers. Binary is used by computers, hexadecimal provides a readable shortcut, and decimal is used for human interaction. Concepts such as MSB, LSB, and nibbles describe the structure of binary data, while signed representations like two’s complement allow negative values. These concepts are fundamental to understanding MIDI messages, high-resolution values, and digital protocols.