Sei sulla pagina 1di 37

ITBP205

Digital Design and Computer


Organization
Unit 2
Number Systems
Prof. Walid Ibrahim

Outline
Generic Number Systems
Decimal, Binary, Octal, and
Hexadecimal
Conversion Between Number
Systems
Addition in base-b
Representing ve numbers in
binary format
2

NUMBER SYSTEMS
A number with base b is represented by a string of digits:

An1 An-2 A1 A0 . A-1 A-2 A-m 1 A- m

in which 0 Ai < b and . is the base point.


3

6 4 8 4 . 3 9 4

The value of the number is calculated using the following


two power series:

Integer Part Fraction part


= 6 x 103 + 4 x 102 + 8 x 10 + 4 + 3 x 10-1 + 9 x 10-2 + 4 x
10-3

Number Systems, Cont.


Decimal Number System (b = 10)
10 Symbols: 0, 1, 3, 4, ,5 ,6 ,7 ,8 ,9

Binary Number System (b = 2)


2 Symbols: 0 , 1

Octal Number System (b = 8)


8 symbols: 0, 1, 2, 3, 4, 5, 6, 7

Hexadecimal (HEX) Number System (b = 16)


16 symbols: 0, 1, 3, 4, ,5 ,6 ,7 ,8 ,9, A, B, C, D, E, F

Numbers in Different Bases


G
o
o
d
id
e
a
to
M
e
m
or
iz
e

Decimal

Binary

Octal

00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16

00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
10000

00
01
02
03
04
05
06
07
10
11
12
13
14
15
16
17
20

Hexadeci
mal
00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
0E
0F
10
5

Digit Weight

Base
Symbols
-5
-4
-3
-2
Digit
-1
Position
0
1
2
3

Genera
l

Decimal

Binary

Octal

10

0 => b
-1

0 => 9

0 => 1

0 => 7

b-5
b-4
b-3
b-2
b-1
b0
b1
b2
b3
b4
b5

10-5 =
0.00001
10-4 =
0.0001
10-3 =
0.001
10-2 =
0.01
10-1 = 0.1
100 = 1
101 = 10

2-5 =
0.03125
2-4 =
0.0625
2-3 =
0.125
2-2 = 0.25
2-1 = 0.5
20 = 1
21 = 2
22 = 4

8-5 = 1/
(8)5
8-4 = 1/
(8)4
8-3 = 1/
(8)3
8-2
=0.01563
8-1=
0.125
80= 1
1

Exercise
What is the value a) 5 x 10
of digit 5 in octal
b) 5 x 82
number 4578?
c) 5 x 8

d) 5 x 2

What is the
value of digit 2
in number
433.125

a) 2
b) 2 x 2-1
c) 2 x 10-2
d) 2 x 5-2

Decimal Counting

0
1
2
3
4
5
6
7
8
9

10
11
12
13
.
.
.
.
98
99

100
101
102
103
.
.
.
.
998
999

1000
1001
1002
1003
.
.
.
.
9998
9999

Octal Counting

0
1
2
3
4
5
6
7

10
11
12
13
.
.
76
77

100
101
102
103
.
.
776
777

1000
1001
1002
1003
.
.
7776
7777

Binary Counting

0000 0010 0100


0001 0011 0101
0110
0111

1000
1001
1010
1011
1100
1101
1110
1111

10

Exercises
In Binary number
system, what
comes after 1010
?

a) 1110
b) 1011

c) 1001
d) 1101

In Hexadecimal
number system,
what comes
after CDF?

a) CDF1
b) CDF0
c) CE0

d) CD0

11

Converting Base-b to Decimal


To convert from and base-b to decimal,
simply multiply each digit by b raised to
the power corresponding to the position
of the digit
Example: Convert 1011.1012 to Decimal

= 123 + 022 + 121 + 120 + 12-1 +


02-2 + 12-3
= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125
= 11.62510
Example: Convert 674.4258 to Decimal

= 682 + 78 + 480 + 48-1 + 28-2 +


58-3
12

Exercises
Convert 3041.2315 to decimal

Convert the HEX number 6AC.B3516 to


Decimal

13

Converting Decimal to Base-b


Separate the whole number and the fraction
parts.
9763 . 625
For the whole number, repeatedly divide the
number by b and keep track of the
remainder. Read the answer from the
bottom up
For the fraction part, repeatedly multiple
the fraction by the based b and keep track
of the whole value. Read the answer from
top down
14

Example
Convert the decimal number 325.512 to
base-5
Number

Division

Remainder

325
65
13

325 / 5 = 65
65 / 5 = 13
13 / 5 = 2

0
0
3

2/5=0

Fraction

Multiplication

Whole Number

0.512

0.512 x 5 =
2.56

0.56
0.56 x 5 = 2.8
0.8
0.8 x 5 = 4.0
Answer: 325.51210 = 2300.2245

2
4
15

Converting Decimal to Binary

16

Converting Decimal to Binary

17

Exercises
Convert the decimal number 95.12510 to
binary

Convert the decimal number 95.12510 to


octal

18

Converting Binary Numbers to Octal


There is a simple way to convert a binary
number to octal (without converting to
decimal first).
Starting from the binary point, group each
three binary digits into one octal digit

Example: convert 101110111.100010 to octal


101110111. 100010
5

. 4

2
19

Converting Octal Numbers to Binary


To convert from octal to binary, simply
expand each octal digit into three binary
digits

Example: convert 712.438 to binary


7

. 4

111001010. 100011
20

Converting Binary Numbers to Hex


Like the octal numbers, there is a simple way
to convert a binary number to the
corresponding Hexadecimal value.
Starting from the binary point, group each
FOUR digits into one Hexadecimal digit

Example: convert 101110111.100010 to octal


000101110111. 10001000
1

8
21

Converting Hex Numbers to Binary


To convert from Hexadecimal to binary,
simply expand each Hex digit into FOUR
binary digits

Example: convert A1C.4B16 to binary


A

101000011100. 01001011
22

Exercises
Convert the Binary number
110101010.101010 to Hex

Convert the Octal number 75.1258 to


Hexadecimal

23

Homework
Complete the following table:
Decimal

Binary

Octal

Hexadeci
mal

11011011.
101
3672.672
528.625
AB9.CD
24

Special Power of 2

210 (1024) is Kilo, denoted "K"


220 (1,048,576) is Mega, denoted
"M"
230 (1,073, 741,824)is Giga,
denoted "G"
240 (1,099,511,627,776 ) is Tera,
denoted T"

25

Number Range
Given N-digit decimal number
You can represent up to 10N possible values
Range is: [0, 10N - 1]
Example
A 3-digit decimal number represents 103 = 1000
possible values,
Range [0, 999]

Given N-bit binary number


You can represent up to 2N possible values
Range is: [0, 2N - 1]
Example
A 3-digit binary number represents 23 = 8 possible
values, with
range of [0, 7] (i.e., 0002 to 1112)
26

Required Number of Digits


Given M elements to be represented by a binary
code, the minimum number of bits, n, needed,
satisfies the following relationships:
2n M > 2(n 1)
Example:
How many digits are required to represent 25 different
values in radix 2?
Answer:
25 25 > 2(5 1)
Then: n = 5

27

Exercises
How many bits are required to represent
64G in base 2?

What is the maximum number of codes


that code be presented with 28 digits in
base 2?

28

Addition in base-b
To add two numbers in base b, do a
repetitive summation starting from the
two least significant digits.
If the sum is r, set sum = sum - b and
set the carry out to 1, otherwise the
carry
Examplout = 0.
es

Co

Su
m

1100

Co

1110

A 938

0110

C A9 7

1111

173CF

Su
m

10101

29

Exercises
What is the result of : 0101112 + 1010112
?

What is the result of: 63758 + 11568?

What is the result of: A34B16 + C45616?

30

Signed Binary Numbers


Sign/Magnitude Numbers
Twos Complement Numbers

31

Sign/Magnitude
1 sign bit, N-1 magnitude bits
Sign bit is the most significant bit (left most)
Negative number: sign bit = 1
Positive number: sign bit = 0
Range of an N-bit sign/magnitude number:
[-2N-1 + 1, 2N-1 - 1]
Problems
Two representations of zero [0000, 1000]
Difficulties in arithmetic operations:
1101 (-5) + 0011 (3) = 0000
32

Exercises
Represent 27 in sign/magnitude format

What is the range of a 6 digit


sign/magnitude number ?

33

Twos Complement Representation


The most significant
bit still indicates the
sign
Same as unsigned
binary, but the value
of the most
significant bit is -2N-1
Example: What is
the value of 10110

Unsigned:
10110 = 16 + 4 + 2 =
22
Twos complement
10110 = -16 + 4
+ 2 = -10

Single
representation of
zero (0000)
Arithmetic works
fine

1011 (-5) + 0011 (3) = 1110 (-8 + 4


+ 2) = -2

34

Twos Complement Representation


What is the twos complement of number 011010

First
meth
od

Complement each
digit to get the first
complement

100101

Add one to the first


complement.

100110

Secon
d
Metho
d

Start from the least


significant bit, locate
the first digit with
value 1
Complement each
digit after the first
digit with value 1.

011010
100110
35

Exercises
Represent 27 twos complement format

What is the range of a 6 digit twos


complement number ?

What is the twos complement of number


10010100?
36

Homework
Solve the following problems from
your textbook unit 1.4, page 30

1.a, 1.d, 1.f


2.a, 2.e
3.a, 3.c
4.c
5.a, 5.d, 5.e
6.a, 6.e, 6.h
7.c, 7.d, 7.h
8.c, 8.d

37

Potrebbero piacerti anche