Anda di halaman 1dari 19

Lecture 3

EC 381

Fall 2017

Mohamed Elgalhud
Important Properties
 How many possible digits can we have in Radix r ?
r digits: 0 to r – 1
 What is the result of adding 1 to the largest digit in Radix r ?
Since digit r is not represented, result is (10)r in Radix r
Examples: 12 + 1 = (10)2 78 + 1 = (10)8
910 + 1 = (10)10 F16 + 1 = (10)16
 What is the largest value using 3 digits in Radix r ?
In binary: (111)2 = 23 – 1
In octal: (777)8 = 83 – 1 In Radix r:
In decimal: (999)10 = 103 – 1 largest value = r 3 – 1

Reference: Lecture Notes of Dr. Samir Elbuni


Important Properties – cont’d
 How many possible values can be represented …
Using n binary digits? 2n values: 0 to 2n – 1
Using n octal digits 8n values: 0 to 8n – 1
Using n decimal digits? 10n values: 0 to 10n – 1
Using n hexadecimal digits 16n values: 0 to 16n – 1
Using n digits in Radix r ? n nr values: 0 to r – 1

Reference: Lecture Notes of Dr. Samir Elbuni


Important Properties of Fractions
 How many fractional values exist with m fraction bits?
2m fractions, because each fraction bit can be 0 or 1
 What is the largest fraction value if m bits are used?
Largest fraction value = 2-1 + 2-2 + … + 2-m = 1 – 2-m
Because if you add 2-m to largest fraction you obtain 1
 In general, what is the largest fraction value if m fraction
digits are used in radix r ?
Largest fraction value = (r -1 + r -2 + … + r -m ) (r – 1)= 1 – r -m
For decimal, largest fraction value = 1 – 10-m
For hexadecimal, largest fraction value = 1 – 16-m

Reference: Lecture Notes of Dr. Samir Elbuni


Complements
 In computers, the representation and manipulation of
negative numbers is often performed using complements

 Complements for a radix come in two forms


1. r’s complement (Radix complement)
2. (r-1)’s complement (Diminished radix complement)

 For binary system -- 2’s complement, & 1’s complement


 For Decimal – 10’s complement, & 9’s complement

5 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


(r-1)’s complement
 Given a +ve number N with n digit integer part & m digit
fractional part
 N = (an-1an-2 …..a0..a-1a-2 ….a-m)
 (r-1)’s complement is defined as
rn – r-m - N
 Examples – 9’s complement
 (37218)10 = 105 – 1 - 37218 = 62781
 (0.12345)10 = 100 – 10-5 - 0.12345 = 0.87654
 Examples – 1’s complement
 (101110)2 = 26 – 20 - 101110 = 111111 -101100 = 010001
 (0.0110)2 = 20 – 2-4 - 0.0110 = 0.1111 – 0.0110 = 0.1001

6 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


r’s complement
 Given a positive number N with n digits
 N = (an-1 an-2 …..a0)
 r’s complement is defined as
 rn – N for N ≠ 0; zero otherwise
 Examples – 10’s complement
 (37218)10 = 105 – 37218 = 62782
 (0.12345)10 = 100 – 0.12345 = 0.87655
 Examples – 2’s complement
 (101110)2 = 26 – 101110 = 010010
 (0.0110)2 = 20 – 0.0110 = 0.1010

7 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Complement
 The complement of a complement returns the original
number
 For binary numbers,
 The 1’s complement of a number is obtained by flipping bits
 The 2’s complement of a number is obtained by flipping bits
and adding 1 (for integer numbers) and adding r-m for real
numbers
 i.e (2’s complement =1’s complement +1 for integer numbers)
 Example
 The 1’s complement of 1011000  0100111 (flip the bits)
 The 2’s complement of 1011000 = 0100111+1=0101000

8 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Complement
 For decimal numbers,
 The 9’s complement is obtained by subtracting each digit from
9.
 The 10’scomplement of N, can be formed also by leaving all
least significant 0’s unchanged, subtracting the first nonzero
least significant digit from 10, and subtracting all higher
significant digits from 9.
 Or 10’s complement = 9’s complement +1
 Example
 9’s complement of 012398 = 999999-012398=987601
 10’s complement of 012398 =987601+1=987602

9 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Subtraction with Complements

 The subtraction of two n‐digit unsigned numbers M - N in


base r can be done as follows:

10 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Subtraction- Example

 [9’s complement of 3250 = 99999-03250=96749


 10’s complement of 3250 =96749+1=96750]

11 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Subtraction- Example

There is no end carry.


 The answer is -(10’s complement of 30718) = -69282.

12 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


 Given the two binary numbers
 X = 1010100 and Y = 1000011, perform the subtraction
 (a) X - Y and (b) Y - X by using 2’s complements.
 1111 carries
2’s complement of
1000011 =
0111100+1=0111101

2’s complement of
1010100 =
0101011+1=0101100

 There is no end carry.


 Y - X = -(2’s complement of 1101111) = -0010001
13 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017
Signed Binary Numbers
 Computers handle signed numbers as well
 Left most bit (Most Significant Bit) represents the sign
0  +ve; 1  -ve
 Both signed and unsigned binary numbers consist of a
string of bits when represented in a computer.
  The user determines whether the number is signed or
unsigned.

14 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Signed Binary Numbers
 Three common representations
 Signed-magnitude representation
 Signed-1’s complement representation
 Signed-2’s complement representation
 For +ve numbers, all three have same representation

15 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Signed Magnitude

 left-most bit indicates sign: positive (0) or negative (1).

 changing only the sign bit

16 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Signed 1’s complement
 The one’s complement of a binary number involves
inverting all bits.
 To find negative of 1’s complement number take the 1’s
complement of whole number including the sign bit.

17 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Signed 2’s complement
 The two’s complement of a binary number involves
inverting all bits and adding 1.
 To find the negative of a signed number take the 2’s
complement of the positive number including the sign bit.

18 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017


Signed Binary Numbers

19 Reference: Lecture Notes of Eng.Yusra Maatog 10/2/2017

Anda mungkin juga menyukai