Вы находитесь на странице: 1из 17

UCCD1133

Introduction to Computer Organisation and Architecture

Slides adapted from


Mok Kai Ming (mokkm@utar.edu.my)

Lecture 2-1
Number Systems and Data Representation
Outline
Count in binary, octal and hexadecimal number systems.
Understand the weighting structure of numbers.
Perform base conversion of various number systems.
Carry out arithmetic operations with binary numbers.
copyright 2009 Mok KM

Number System
Digital systems process data in binary format.
Need to represent information in binary
For manipulation in electronic hardware
A number system consists of an ordered set of symbols called digits.
Total number of digits = base (radix, R) of a number system
The range of numbers is 0 to (R - 1). Decimal Binary Octal Hexadecimal
The number can have 2 parts: 0 0 0 0
- Integer
1 1 1 1
- Fractional
2 10 2 2
- Separated by a radix point (.)
3 11 3 3
- E.g. (an-1 an-2 ... a1 a0 . a-1 a-2 ... a-m)R 4 100 4 4
Commonly used number systems in digital 5 101 5 5
electronics field of study 6 110 6 6
Decimal number system: 7 111 7 7
- Digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} 8 1000 10 8
- R = 10. 9 1001 11 9
Binary number system: 10 1010 12 a
- Digits {0, 1} 11 1011 13 b
- R = 2. 12 1100 14 c
Hexadecimal number system: 13 1101 15 d
- Digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} 14 1110 16 e
- R = 16.
15 1111 17 f
Octal number system:
16 10000 20 10
- Digits {0, 1, 2, 3, 4, 5, 6, 7}
- R = 8.
copyright 2009 Mok KM

Counting in Binary
How to count in binary?
0 First column is full
1 Reset first column and add 1 to second column
10 First two columns are full
11 Reset and add 1 to third column
100
101
110
111 First three columns are full
1000 Reset and add 1 to fourth column
1001

With N bits, can count up to (2N 1) for a total of 2N different numbers


copyright 2009 Mok KM

Weighting Structure of Numbers


A positive number, N written in positional notation

N = (an-1 an-2 ... a1 a0 . a-1 a-2 ... a-m)R


= an-1 Rn-1 + an-2 Rn-2 + ... + a1 R1 + a0 R0 + a-1 R-1 + a-2 R-2 + ... + a-m R-m

Where
. = radix point. E.g. binary point, hex point, decimal point.
R = radix or base - any positive integer where R > 1
n = number of integer digits (left of radix pt)
m = number of fractional digits (right of radix pt)
an-1 = most significant digit (MSD)
a-m = least significant digit (LSD)

Each digits position is multiplied by a weighting factor (an integral power of


R depending on the position)
Example, N = 251.4110.
= (2 x 102) + (5 x 101) + (1 x 100) + (4 x 10-1) + (1 x 10-2)

10n-1 .. 102 101 100 . 10-1 10-2 .. 10-n


2 5 1 . 4 1
copyright 2009 Mok KM

Weighting Structure of Numbers


Example, binary weight structure
2n-1 22 21 20 .2-1 2-2 2-n

Positive Powers of 2 Negative Powers of 2


(Integer Number) (Fractional number)
27 26 25 24 23 22 21 20 2-1 2-2 2-3 2-4 2-5 2-6
128 64 32 16 8 4 2 1 1/2 1/4 1/8 1/16 1/32 1/64

Right-most bit is the LSB (Least Significant Bit).


Left-most bit is the MSB (Most Significant Bit).
copyright 2009 Mok KM
Base Conversion:
Convert Base N to Decimal (Base 10)
Example 1
Convert 1010.1012 to ?10.

Solution 1
1010.1012 = (1 X 23) + (0 X 22) + (1 X 21) + (0 X 20) + (1 X 2-1) + (0 X 2-2) + (1 X 2-3)
= 810 + 0 + 210 + 0 + 0.510 + 0 + 0.12510
= 10.62510

Example 2
Convert 6278 to ?10.

Solution 2
6278 = (6 X 82) + (2 X 81) + (7 X 80)
= 38410 + 1610 + 710
= 40710
copyright 2009 Mok KM
Base Conversion:
Convert Integer Decimal (Base 10) to Base N
Example 1: Method 1 Example 2: Method 2 - Divide-by-
Convert 4910 to a binary number. radix
Convert 4910 to a binary number.
Solution 1
49 32 = 17 Solution 2
17 16 = 1 49 / 2 = 24 remainder 1 (LSB)
1 1 = 0 (conversion completed) 24 / 2 = 12 remainder 0
12 / 2 = 6 remainder 0
6/2 =3 remainder 0
3/2 =1 remainder 1
64 32 16 8 4 2 1 1/2 =0 remainder 1 (MSB)
1 1 0 0 0 1

Therefore, 4910 = 1100012 Therefore, 4910 = 1100012


copyright 2009 Mok KM
Base Conversion:
Convert Fractional Decimal (Base 10) to Base N
Example 1: Method 1
Convert 0.82812510 to a binary number.

Solution 1
0.828125 0.5 = 0.328125
0.328125 0.25 = 0.078125
0.078125 0.0625 = 0.015625
0.015625 0.015625 = 0 (conversion completed)

0.5 0.25 0.125 0.0625 0.03125 0.015625


1 1 0 1 0 1

Therefore, 0.82812510 = 0.1101012


copyright 2009 Mok KM
Base Conversion:
Convert Fractional Decimal (Base 10) to Base N
Example 2: Method 2: Multiply-by-radix
Convert 0.82812510 to a binary number.

Solution 2
MSB 1.656250 <- 0.828125 X 2
1.312500 <- 0.656250 X 2
0.626000 <- 0.312500 X 2
1.250000 <- 0.625000 X 2
0.500000 <- 0.250000 X 2
LSB 1.000000 <- 0.500000 X 2

Continue multiplying until the desired number of decimal places is reached or


when the fractional part is all zeros i.e. 1.000000.

Therefore, 0.82812510 = 0.1101012


copyright 2009 Mok KM
Base Conversion:
Convert Base N to Base M
Requires an intermediate conversion step
First convert base N to base 10
Then base 10 to base M.

Example 1:
Convert 18.69 to ?11.

Solution 1
Convert 18.69 to base 10:
18.69 = (1 X 91) + (8 X 90) + (6 X 9-1)
= 9 + 8 + 0.666
= 17.66610
Convert from base 10 to base 11 using the divide-by-radix and multiply-by-radix method:
17 / 11 = 1 remainder 6
1 / 11 = 0 remainder 1

7.326 <- 0.666 X 11


3.586 <- 0.326 X 11
6.446 <- 0.586 X 11

Therefore, 18.69 = 016.73611 = 16.73611


copyright 2009 Mok KM
Base Conversion:
Convert Base N to Base M When M = NK
Example 1:
Convert 1011011.10101112 to base 8.

Solution 1
Since 8 = 23, we can group three binary digits for each octal digit.
Therefore, 1_011_011.101_011_12 = 133.5348

Example 2
Convert AF.16C16 to base 8.

Solution 2
Since 16 is not a power of base 8. But both bases are a power of 2.
Therefore, we can convert AF.16C16 to base 2 and then convert to base 8.

Firstly, each hex digit is replaced by 4 bin digits.


AF.16C16 = 1010_1111.0001_0110_11002

Then convert the bin number to base 8.


10_101_111.000_101_101_1002 = 257.05548

Therefore, AF.16C16 = 257.05548.


copyright 2009 Mok KM

Binary Arithmetic
4 basic types of binary arithmetic:
Binary addition
Binary subtraction
Binary multiplication
Binary division
copyright 2009 Mok KM

Binary Addition
Example 1 How does the above information relate
Add 11110 and 1100. to circuit?
Understand the process of binary
addition leads to constructing an adder
Solution 1 circuit for each bit
1 1 1 1 0 Augend Then combine the adders to compute
1 1 1 0 0 0 Carries two n-bit numbers
+ 0 1 1 0 0 Addend Need to capture the info into an
0 1 0 1 0 Sum
intermediate form first e.g. truth table
before proceed to adder circuit design.

When two n-bit numbers are added,


the result is a (n+1)-bit number Inputs Outputs
Carry-in A B Carry-out Sum
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
copyright 2009 Mok KM

Binary Subtraction
Example 1
Subtract 101110 from 1100101.

Solution 1

1 1 0 0 1 0 1 Minuend
0 1 1 1 1 1 0 0 Borrows
- 0 1 0 1 1 1 0 Subtrahend
0 1 1 0 1 1 1 Difference

bin x y bout diff


0 0 0 0 0
0 0 1 1 1
0 1 0 0 1
0 1 1 0 0
1 0 0 1 1
1 0 1 1 0
1 1 0 0 0
1 1 1 1 1
copyright 2009 Mok KM

Binary Multiplication
Example 1
Multiply 10111 by 1010.

Solution 1

10 1 11 Multiplicand
X 1 0 10 Multiplier
00 0 00 First partial product
1 01 1 1 Second partial product
00 00 0 Third partial product
101 11 Fourth partial product
111 00 110 Product

m bits x n bits = m+n bit product


copyright 2009 Mok KM

Binary Division
Example 1
Divide 111101 by 1001.

Solution 1

110 Quotient
Divider 1 0 0 1 1 1 1 1 0 1 Dividend
1001
1100
1001
111 Remainder

Вам также может понравиться