| UMBC | CMSC 313 -- Assembly Language Segment | Previous | Next |
Each symbol represents a unique value. You are familiar with the decimal system, using the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. The decimal system is based on the powers of 10.When we want to represent a value greater than 9, we use a compound system, where the right-most symbol is one power of ten lower that its neighbor on the left.
3 times 100 102 300
9 times 10 101 90
7 times 1 100 7
---
397
The most common powers of two and values (which are the ones you are expected to know) are:
| 20 | 1 |
| 21 | 2 |
| 22 | 4 |
| 23 | 8 |
| 24 | 16 |
| 25 | 32 |
| 26 | 64 |
| 27 | 128 |
| 28 | 256 |
| 29 | 512 |
| 210 | 1024 |
| 211 | 2048 |
| 212 | 4096 |
| 213 | 8192 |
| 214 | 16384 |
| 215 | 32768 |
| 216 | 65536 |
To convert a binary number to decimal, simply add up the decimal equivalents of the positions in the value that are non-zero This leads to 10112 being converted as:
1 times 8 23 8 (decimal)
0 times 4 22 0 (decimal)
1 times 2 21 2 (decimal)
1 times 1 20 1 (decimal)
---
11 (decimal)
Examination of this example should reveal that we used the same concepts, but substituted two for ten as the base.
To convert a decimal number to binary, we can use subtraction to reverse the process. (Note: There are other methods, but this only involves adding and subtractings.)
First, find the largest power of two that does not exceed the value to be converted. If we wish to convert the number 24010 to binary, we can see from the chart the we are looking for 12810 or 27. That means that there are eight positions in the binary equivalent (have to account for 20) and the left-most is set to 1.
1 _ _ _ _ _ _ _2
240 -128 ---- 112
Well, 64 can be subtracted, so:
112 11 _ _ _ _ _ _2 - 64 ---- 48
48 111 _ _ _ _ _2 - 32 ---- 16
16 1111 _ _ _ _2 - 16 ---- 0
0 11110 _ _ _2
0 111100 _ _2
0 1111000 _2
0 111100002
This leads to FE08:
F times 4096 163 61440 (decimal)
E times 256 162 3584 (decimal)
0 times 16 161 0 (decimal)
8 times 1 160 8 (decimal)
-----
65032 (decimal)
| Binary | Decimal | Hex |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | 10 | A |
| 1011 | 11 | B |
| 1100 | 12 | C |
| 1101 | 13 | D |
| 1110 | 14 | E |
| 1111 | 15 | F |
One of the things to note, the value 0000 is exactly the same value as 0. Leading zeroes do not alter a value. When working with binary and hex values, it is common to write them as 8-, 16-, or 32-bit values by adding the necessary leading zeroes.
F E 0 8 1111 1110 0000 1000
Then convert each four bit group to hex:
1111 1110 0000 1000 F E 0 8