CS114 Lab: Decimal, Binary, Hexadecimal Systems
Representation of Numbers and the Binary System
Inside a computer, numbers are represented using the Binary System, as you know.
Learn the first 10 powers of 2:
power | 2 to the power (in decimal) |
0 | 1 |
1 | 2 |
2 | 4 |
3 | 8 |
4 | 16 |
5 | 32 |
6 | 64 |
7 | 128 |
8 | 256 |
9 | 512 |
10 | 1024 |
Decimal and Binary values from 0 to 15:
Decimal Value | Binary Value |
0 | 0 |
1 | 1 |
2 | 10 |
3 | 11 |
4 | 100 |
5 | 101 |
6 | 110 |
7 | 111 |
8 | 1000 |
9 | 1001 |
10 | 1010 |
11 | 1011 |
12 | 1100 |
13 | 1101 |
14 | 1110 |
15 | 1111 |
Binary to Decimal
You already know how to do this. As a reminder, number 10011 in binary is the same as
19 in decimal, because:
1*16 + 0*8 + 0*4 + 1*2 + 1*1 = 19
- Convert the following binary numbers into decimal:
- 00000000 -->
- 00001111 -->
- 01101011 -->
- 11111111 -->
- 00000000 00000000 -->
- 00000000 11111111 -->
- 00000010 01100011 -->
- 00000001 01100011 -->
Decimal to Binary
To convert a decimal number to the binary equivalanr, we need to express the
decimal number as a sum of powers of 2. Based on this, write down an 1 for every
power that appears in the sume, and a 0 for each that does not.
Pad it up with leading zeros so that you get a whole number of bytes.
Here is an example:
113(decimal) = 1*64 + 1*32 + 1*16 + 1*1 =
1*64 + 1*32 + 1*16 + 0*8 + 0*4 + 0*2 + 1*1 --> 01110001 (binary)
- Convert the following decimal numbers into binary:
- 70 -->
- 25 -->
- 49 -->
- 63 -->
- 231 -->
- 513 -->
- 623 -->
- 640 -->