This post is the first one in the series about x86 Assembly. Topics to cover:
- Bases & Conversion
The most you can carry out of a single-column addition of 2 numbers is 1
Base 8 (Octal)
Octal |
---|
1 = 80 |
10 = 81 |
100 = 82 |
1000 = 83 |
Base 8 – Base 10
76225 (base 8)
= 80 * 5
+ 81 * 2
+ 82 * 2
+ 83 * 6
+ 84 * 7
= 31893 (base 10)
Base 16 (Hex)
Base 16 – Base 10
8DB3H (base 16)
= 160 * 3
+ 161 * 11
+ 162 * 13
+ 163 * 8
= 36275 (base 10)
Base 10 – Base 16 (余数法, next smallest number)
413 (base 10)
= 162 * 1
+ 161 * 9
+ 160 * 13
= 19DH (base 16)
Base 2 (Binary)
In real world, counting tells how many are there;
In CS, counting is about naming them,
In binary, a column’s value is either present (1) or not present (0).
Hex as Shorthand for Binary
Decimal | Hex | Binary |
---|---|---|
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 2 | 0010 |
3 | 3 | 0011 |
4 | 4 | 0100 |
5 | 5 | 0101 |
6 | 6 | 0110 |
7 | 7 | 0111 |
8 | 8 | 1000 |
9 | 9 | 1001 |
10 | A | 1010 |
11 | B | 1011 |
12 | C | 1100 |
13 | D | 1101 |
14 | E | 1110 |
15 | F | 1111 |
Converting every 4 binary digits (right to left) into a single hex digit.
1 | Decimal 218 |