You are on page 1of 5

COE/EE 243 Lecture #2

Correction: authors web site is: http://www.ddpp.com/student/student.html


** Number Systems
Any positive integer R (R > 1) can be used as a radix or base
of a number system.
If the base is R, then R (0, 1, 2, ... R-1) digits are needed
to represent any number in that base.
Numbers written in positional notation can be written in a
power series of R.
Example in base 2: (converting to decimal)
(0 1 are our only digits)

2 1 0 -1 -2
101.01 = 1 x 2 + 0 x 2 + 1 x 2 + 0 x 2 + 1 x 2
2
= 4 + 1 + 1/4 = 5.25 in decimal
or:

(000) = 0
2 10
(001) = 1
2 10
(010) = 2
2 10
(011) = 3
2 10
(100) = 4
2 10
(101) = 5
2 10
(110) = 6
2 10
(111) = 7
2 10

Or in base 8 (octal)
(0 1 2 3 4 5 6 7)
2 1 0 -1 -2
101.01 = 1 x 8 + 0 x 8 + 1 x 8 + 0 x 8 + 1 x 8
8
= 64 + 1 + 1/64 = 65.015625
10
Or a number in base 16 (hexadecimal) we run out of numbers and use
letters...
0 1 2 3 4 5 6 7 8 9 A B C D E F
where A = 10
B = 11
.
.
.
F = 15
1 0
3F = 3 x 16 + 15 x 16 = 48 + 15 = 63
16 10
Binary, Octal, and Hexadecimal have all see extensive use in microprocessors
and low level languages. Since they aren't commonly used within the
application, it is necessary to convert between to and from decimal.
* Converting a number N from Decimal to Base R
To convert a decimal number N to a base R number:
Notice that N = (a a ... a a a )
n n-1 2 1 0 R
n n-1 1
N = a R + a R + ... + a R + a
n n-1 1 0
Divide N by R to get Q remainder a
1 0
n-1 n-2 1
Q = a R + a R + ... + a R + a
1 n n-1 2 1

Divide Q by R to get Q remainder a
1 2 1
Repeat process until a is found.
n
Convert 59 to a binary number:
59 / 2 = 29 rem 1 --> a = 1
0
29 / 2 = 14 rem 1 --> a = 1
1
14 / 2 = 7 rem 0 --> a = 0
2
7 / 2 = 3 rem 1 --> a = 1
3
3 / 2 = 1 rem 1 --> a = 1
4
1 / 1 = 0 rem 1 --> a = 1
5
(111011)
2
Check your work! --> 1 + 2 + 8 + 16 + 32 = 59
Example: (67) to base 8
10
67/8 = 8 Rem 3 ---> a = 3
0

8/8 = 1 Rem 0 ---> a = 0
1
1/8 = 0 Rem 1 ---> a = 1 ----> (103)
2 8
To convert a decimal fraction F to base R:
Notice that F = (.a a ... a )
-1 -2 -m R
Multiply F by R to get a + F
-1 1

Multiply F by R to get a + F
1 -2 2

Repeat process until a is found or process repeats.
m
Convert 0.4 to a binary number:
.4 x 2 = 0.8 --> a = 0
-1
.8 x 2 = 1.6 --> a = 1
-2
.6 x 2 = 1.2 --> a = 1
-3
.2 x 2 = 0.4 --> a = 0
-4
We're back to 0.4, the sequence will repeat.....
0.4 = (0.0110 0110 0110 ...)
2
There is no exact representation of 0.4 as a binary number!
Thus, computers must approximate some numbers.
If we have a number like (123.456) then we convert the
123 by dividing by R and using the remainder and the
decimal fraction by multiplying by R
Converting between binary and octal and binary and hexadecimal
is easily done by inspection because each octal digit corresponds
to exactly three binary digits and each hexadecimal digit
corresponds to exactly 4 binary digits. Always start from the
radix point and work outward when grouping. Add extra zeros at
far right and far left when needed to make 3 or 4 digits
(1000111.011001) to octal and hexadecimal
2
To base 8: (re-write in groups of 3)

(001 000 111 . 011 001) = (1 0 7 . 3 1)
2 8
To base 16: (re-write in groups of 4)
(0100 0111 . 0110 0100) = (4 7 . 6 4)
2 16
notice where the extra zeros at start and end
(F C 2 . 7) = (1111 1100 0010 . 0111)
16 2
If you want to convert from hexadecimal to octal, it
is easier to convert to binary as an intermediate step

You should practice you conversion from binary numbers to
digits in bases 8, 10 and 16
** Binary Arithmetic
Arithmetic is usually done in binary in digital systems
because such logic networks are easier to design.
The methods for binary addition, subtraction, multiplication,
and division are the same as for decimal addition, etc.
except that everything is done in powers of 2.
Add 5 + 12 in binary:
11 -- carries
00101 = 5
+01100 = 12
------
10001 = 17
Subtraction: 0 - 0 = 0
0 - 1 = 1 (borrow 1 from next column)
1 - 0 = 1
1 - 1 = 0

Subtract 5 from 12 in binary:
111 -- borrows (for example col 3 is: -1 + 1 -1)
01100 = 12
-00101 = 5
------
00111
However, it is more common to add a positive number to a negative
number.

You might also like