Most Significant Bit (MSB) and Least Significant Bit (LSB)
In a number systems, the digit with the most weight is called MSD (Most Significant Digit) and the digit with least weight, LSD (Least Significant Digit). But when talking specifically about binary, a different notation is used; MSB (Most Significant Bit) and LSB(Least Significant Bit).
MSB | LSB | |||
Bits | 1 | 0 | 1 | 1 |
Endianness, is the order of stored information. There are two ways of storing information, big-endian (BE), where the MSB is stored first, and little-endian (LE) where the LSB is stored first.
This is a simplification, but just know that BE and LE exists, and that you can’t blindly convert between them with disregard.
Different number systems
Besides decimal (base-10) and binary (base-2), there exists two other number systems; hexadecimal number system, and the octal number system. The hexadecimal system is widely used because you can conveniently represent larger binary numbers. The reason why these systems are used, is because of the ease of conversion between the different systems.
Let’s consider a hexadecimal number. Instead of using a base of 2 (binary) or 10 (decimal), hexadecimal uses a base of 16.
To represent 16 different values in a single digit, hexadecimal uses both numbers and letters:
Hexadecimal Digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Here, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 in decimal.
And the octal number system uses a base of 8.
Octal Digits:
0, 1, 2, 3, 4, 5, 6, 7
It’s now obvious that the smaller the base is, the more numbers is needed to represent a number range.
Let’s see how the numbers 0 to 15 looks like in some different bases:
Base 2 |
0000 |
0001 |
0010 |
0011 |
0100 |
0101 |
0110 |
0111 |
1000 |
1001 |
1010 |
1011 |
1100 |
1101 |
1110 |
1111 |
Base 8 |
00 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
Base 10 |
00 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
10 |
11 |
12 |
13 |
14 |
15 |
Base 16 |
0 |
01 |
02 |
03 |
04 |
05 |
06 |
07 |
08 |
09 |
0A |
0B |
0C |
0D |
0E |
0F |
Number system notation
When working with different number systems, it’s important to use the correct notation to distinguish between them. Here’s how different number systems are notated:
Decimal (base-10)
- Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Subscript notation: 2510
Binary (base-2)
- Digits: 0, 1
- Subscript notation: 110012
- Prefix:
0b
. Example:0b11001
Octal (base-8)
- Digits: 0, 1, 2, 3, 4, 5, 6, 7
- Subscript notation: 318
- Prefix:
0o
. Example:0o31
Hexadecimal (base-16)
- Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
- Subscript notation: 1916
- Prefix:
0x
. Example:0x19
General Notation Rule
For clarity, numbers in different bases can be written using subscript notation:
numberbase
Examples:
- 10102 = 1010 (Binary to Decimal)
- 178 = 1510 (Octal to Decimal)
- 1F416 = 50010 (Hexadecimal to Decimal)
In programming, prefixes (0b
, 0o
, 0x
) are used instead of subscripts.