# Intro to Computer Systems

## Number Systems

### Binary Numbers

Some quick facts on binary numbers:

• The base for binary numbers is 2
• The symbols are: 0,1

Similarly to decimals, the positional value of each binary digit indicates the correspond­ing power of 2, as follows:

 Digit Power Exponent 1 1 0 0 1 1 0 1 128 64 32 16 8 4 2 1 27 26 25 24 23 22 21 20

Thus, according to this table, the number 11001101 is equivalent to the decimal:

1 * 27 + 1 * 26 + 0 * 25 + 0 * 24 + 1 * 23 + 1 * 22 + 0 * 21 + 1 * 20
= 128+64+8+4+1
= 205

Note: We are calculating the expression above, using the decimal operations that we know.

Find the decimal equivalent of the binary numbers:

%1101 =
%1111111 =
%10000000 =

Some numbers have meaning for different bases, such as 10010 which may be a binary, octal, decimal or hexadecimal number. Hence, it is often necessary to indicate the basis with a little subindex, such as in 100102, 745628 and 7456210. Sometimes a prefix is used, such as % for binary and \$ for hexadecimal.

#### Counting in Binary

Decimal Binary Decimal Binary
0
00000
10
1
00001
11
2
00010
12
3
00011
13
4
14
5
15
6
16
7
17
8
18
9
19
Complete the table.

As we have seen, binary numbers are very easy for computers to store and manipulate, but for humans they are quite uncomfortable to remember and use. The number 010111100110011111000000101 is very hard to remember for a human being, while its equivalent in hexadecimal - as we shall see - is AF33D05, which is much easier to recall.

Quick facts:

• The base for hexadecimal numbers is 16.
• The symbols are: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
 Positional Values Decimal Values 164 163 162 161 160 65536 4096 256 16 1

Therefore, the number:

1D7E16
= 1 * 163 + D * 162 + 7 * 161 + E * 160
= 1 * 4096 + 13 * 256 + 7 * 16 + 14 * 1
= 755010

Convert the following numbers to decimal:

\$7E =
\$A8 =
\$13BF =

Decimal Hex Decimal Hex
0
0
10
A
1
1
11
B
2
2
12
3
3
13
4
4
14
5
5
15
6
6
16
7
7
17
8
8
18
9
9
19
Complete the table.

Hexadecimals are inconvenient because they need extra symbols (A-E), but on the other hand they are very useful because each hexa-digit is 4 bits (one nibble), and so a byte is represented neatly by two hexa-digits, as in:

1110 1110 = EE
1111 0110 = F6
1010 0001 = A1

Thus, the most common way to display bytes to human beings is with a two-digit hexadecimal number.

## Conversions Between Number Systems

### Binary to Decimal

Since we know how to operate in decimal, using the positional value of each digit, we can calculate the decimal expression of a binary number:

 24 23 22 21 20 1610 810 410 210 110

For example:

101012
= 1 * 16 + 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1
= 16 + 0 + 4 + 0 + 1
= 2110

Convert the following binary values to decimal:

01110 =
11110 =
01101110 =
11100111 =

### Decimal to Binary

Repeatedly divide by 2 until the quotient is zero; for example, to convert 2810 to binary:

2) 28
2) 14 (remainder 0)
2) 7 (remainder 0)
2) 3 (remainder 1)
2) 1 (remainder 1)
2) 0 (remainder 1)
quotient is zero - stop

In the algorithm above, the resulting binary number (from the remainder) should be read upwards.

Therefore, 2810 = 111002

1. Convert the following decimal numbers to binary:

8
17
32
64
127
128
255

2. What is the largest number that may be represented using 4 bits? 8 bits? 16 bits? and 32 bits?

3. How many bits do you need to represent 100010? and 10000010? and 10000000010?

To convert from decimal to hexadecimal the process is the same as above, except now we divide by 16. For example, to convert 34510 to hexadecimal:

16) 345
16) 21 (remainder 9)
16) 1 (remainder 5)
16) 0 (remainder 1)
quotient is zero - stop

Thus 34510 = 15916

16) 74
16) 4 (remainder 10 - i.e. A)
16) 0 (remainder 4)
quotient is zero - stop

Thus 74 10 = 4A16

As we said before, the main advantage of using hexadecimals is that they are convenient for human beings to use, and that it is very easy to convert between them and binary. To convert hexadecimal to binary, write each hexadecimal digit as a 4-bit binary number and put it all together as in the following example:

 Hexadecimal Binary F D 6 9 A 1111 1101 0110 1001 1010

The binary expression of \$FD69A is %11111101011010011010. Again, remember that since a byte is 8 bits, each memory location may be represented exactly by two hexadecimal digits.

Convert the following hexadecimal values to binary:

\$FE45 =
\$BBB775 =
\$ABCDEF =