Title: ECSE2610 Computer Components
1ECSE-2610Computer Components Operations
(CoCO)Fall 2008
Number Systems Representation Binary Arithmetic
Read Sections 2.1-2.6 except starred subsections
2Decimal Representation 10 digits 0,1,2,...,9
Positional Number Notation Weight of each digit
determined by its position.
Example 246 200 40
6 2 x 102 4 x 101 6 x 100
In general, for the Base 10 representation N
? Ni x 10i where each Ni ? 0, 1, 2, . . . ,
9 is the weight on the base raised to the
exponent i. Note Decimal fractions occur when i
is negative 0.35 3 x 10-1 5 x 10-2
3Binary Representation 2 digits 0, 1
Positional Number Notation for the Binary
Representation
N ? Ni x 2i with each Ni ? 0,1
Example Converting 1110012 from binary to
decimal 1110012 1000002 100002 10002
0002 002 12 1 x 25 1 x 24
1 x 23 0 x 22 0 x 21 1 x 20 1 x
32 1 x 16 1 x 8 0 x 4 0 x 2 1
x 1 5710
Easy!
4Quote of the Day
- There are 10 kinds of people in this world
-
- Those who understand binary
- and those who dont.
5Hexadecimal (Hex) Representation 16 digits
0,1,2,...,9,A,B,C,D,E,F
Positional Number Notation for the Hexadecimal
Representation
Note A - F represent the decimal values 10 -
15, respectively.
N ? Ni x 16i with each Ni ? 0,1,2,. .
.,9,A,B,C,D,E,F
Example Converting 8A9B16 from Hex to Decimal
representation 8A9B16 800016 A0016
9016 B16 8 x 163 A x 162 9 x
161 B x 160 8 x 4096 10 x 256 9 x 16
11 x 1 3548310
Still pretty easy! (if you remember 163 4096)
6Converting Decimal to Binary Successive
Division
Idea Use remainders from dividing the decimal
number by powers of 2.
Example Convert 5710 to Binary 57 / 2 28,
remainder 1 (binary number will end with 1) 28
/ 2 14, remainder 0 14 / 2 7, remainder
0 7 / 2 3, remainder 1 3 / 2 1,
remainder 1 1 / 2 0, remainder 1
(binary number will start with 1) Collecting the
remainders (from the bottom up), 5710 1110012
Comes from (((((0x2 1)x2 1)x2 1)x2
0)x2 0)x2 1
1x32 1x16 1x8 0x4 0x2 1x1 57
quotient 0. Time to stop.
7Converting Between Hexadecimal and Binary
Example Convert 1110110001110001012 to
hexadecimal. 1110110001110001012
Hex Binary Decimal 0 0000 0 1 0001
1 2 0010 2 3 0011 3 4 0100 4 5
0101 5 6 0110 6 7 0111 7 8 1000
8 9 1001 9 A 1010 10 B 1011 11 C 1100
12 D 1101 13 E 1110 14 F 1111 15
So 1110110001110001012 3B1C516
Memorize this table!It makes conversions between
hexadecimal and binary easy.
Even easier to go the other way (Hex to Bin)
8BINARY ARITHMETIC
- Computers have circuits that do binary
arithmetic. - You already know the rules for decimal addition
and subtraction (how to handle sums, carries,
differences, and borrows). - Analogously, we develop the rules for binary
addition and subtraction.
9Decimal Addition Refresher
1 x 102 (31) x 101 3 x 100
10Binary Addition of 2 Bits
This table calculates the sum for pairs of binary
numbers
0 0 0 0 1 1 1 0 1 1 1 0 with a
carry of 1
Also known as the Half Adder Table
11Binary Addition of 3 Bits (including Carry)
Table shows all the possible sums for binary
numbers with carries
carry addend augend
sum 0 0 0 0 0 0 1 1 0 1 0
1 0 1 1 0 with a carry of
1 1 0 0 1 1 0 1 0 with a carry
of 1 1 1 0 0 with a carry of
1 1 1 1 1 with a carry of 1
Also known as the Full Adder Table
12Binary Addition Similar to the Decimal Case
Example Add 5 and 3 in binary
(carries) 1 0 12 510 1 12
310 810
13Decimal Subtraction Refresher
9510 1610 7910
Note Borrows are shown as explicit subtractions.
14Binary Subtraction for 2 Bits
This table calculates the difference for pairs of
binary numbers
0 - 0 0 0 - 1 1 with a borrow of 1 1 - 0
1 1 - 1 0
Also known as the Half Subtractor Table
15Binary Subtraction for 3 Bits (including Borrow)
This shows all the possible differences for
binary numbers with borrows
minuend subtrahend borrow difference 0 - 0
- 0 0 0 - 0 - 1 1 with a borrow of 1
0 - 1 - 0 1 with a borrow of
1 0 - 1 - 1 0 with a borrow of
1 1 - 0 - 0 1 1 - 0 - 1 0
1 - 1 - 0 0 1 - 1 - 1 1 with a borrow
of 1
Also known as the Full Subtractor Table
16Binary Subtraction Similar to the Decimal Case
Hanging borrow tells us that result is negative
Example 5 - 3
Example 3 - 5
1 0 12 510 - 1 12 310 1 02
210
1
10
0 1 12 310 - 1 0 12 510 1 02
-210
- 1 0 (borrows)
0
1
Next, we will learn about ways to represent
negative numbers.
17Number Systems Representation of Integers
- Positive numbers are same in most systems
- Major difference is in how negative numbers are
represented - Two major schemes
- signed-magnitude twos-complement
- For example, assume a 4 bit machine word
- 16 different values can be represented
- roughly half are positive, half are negative
18Signed-Magnitude Representation 4 Bit Example
- Sign is high order bit 0 positive or zero
(non-negative) - 1 negative
- Magnitude is three low order bits 0 000 thru 7
111 - Number range ?7 for 4 bit numbers for n bits,
?(2n-1 -1)
19Signed-Magnitude Operations in Computers
- Addition is performed by
- Binary addition when signs of operand the same
- Binary subtraction when signs of operands differ
- Must compare magnitudes to determine sign of
result - Subtraction is performed by
- Binary subtraction when signs of operand the same
- Binary addition when signs of operands differ
- Must compare magnitudes to determine sign of
result - Complicated implementation for
- Adder unit
- Subtractor unit
- Comparator unit
20Twos-Complement Representation 4 Bit Example
Most commonly used system in arithmetic logic
- Only one representation for 0 (0000)
- One more negative number than positive number
- The MSB (most significant bit) indicates the sign
- Positive numbers are the same as in
Signed-Magnitude - But how do we get 1101 -3? . . .
21Negative Numbers in Twos-Complement
Mathematical Method
Let -N denote negative of N in 2s complement.
-N can be calculated by -N 2n - N
22Negative Numbers in Twos-Complement
Simple Method
-N can be calculated by -N 2n N (2n 1)
N) 1 But (2n 1) 111 A string of n
1s So ((2n 1) N)) is the bit by bit
complement of N
23Twos-Complement Operations
- Addition
- Addition not dependent on the signs of operand
- No need to compare magnitudes to determine sign
of result - Subtraction
- Subtraction is treated as an addition
- Add the negative of the subtrahend to the minuend
- Simple implementation
- Adder unit
- Negation circuit unit
Simpler addition/subtraction scheme makes
twos-complement the most common choice for
integer number systems within digital systems