Lecture 9 Numbering Systems 4

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Introduction to Computers

Lecture 9: Numbering Systems-4


Taxonomy of Binary Integers
Representations
Signed vs.
unsigned?
When to use each?
Both are useful.
oAge ? Year? Speed ? X‐value?
oMemory addresses are always unsigned.
Using the same number of bits, unsigned integers can
express twice as many values as signed numbers.
Representing Signed Integers
in Binary
Representations of signed integers:
1. Sign‐and‐Magnitude
2. One’s Complement
They represent integer values
3. Two’s Complement inside computers & have
additional properties that
4. Excess Notation make them compatible with
H/W design.
1‐ Sign‐and‐Magnitude
 The easiest representation
 The leftmost bit represents the sign of the number.

0 if positive and 1 if negative


Sign‐and‐Magnitude :Example-
1

a) +710 = 0 0 0 0 0 1 1 12
(–710 = 100001112)

b) –1010 = 1 0 0 0 1 0 1 02
(+1010 = 000010102)
What is the problem with this notation ?
Sign‐and‐Magnitude – Example
2

Example : 510 + 310 = 0001012 + 0000112


= 0010002 = 810
Example: (–3) 10 + (–4) 10
If both numbers are negative Add |X| and |Y| and
= 1000112 + 1001002
set the sign bit = 1 to the result, Z
= 1001112 = –710

Example (–2) + (+4) = 1000102 + 0001002 If | +ve Number | > | –ve Number |
Set the sign bit of the –ve number to 0 (+ve), so
= 0001002 – 0000102 that both numbers become +ve.
= 0000102 = 210 Subtract the number of smaller magnitude from
the number with a bigger magnitude
One’s Complement
 Positive numbers are same as in sign‐and‐magnitude
Example: +510 = 000001012 (8 bit)
 as in sign‐and‐magnitude representation

For negative numbers, their representations are obtained by


changing bit 0 → 1 and 1 → 0 from their positive numbers
Example: +510
= 000001012
‐510 =
111110102 (8 bit)
It almost like inverting the bits.
One’s Complement – Example 1
Get the representation of one’s complement (8 bit) for the following
numbers:
i) +710 ii) –1010

Solution: Solution:

(+7) = 000001112
(+10)10 = 0 0 0 0 1 0 1 02

So,
(-10)10 = 1 1 1 1 0 1 0 12
One’s Compliment‐ Example 2
 For example, in 8‐bit one’s complement,
 3 is: 00000011
 ‐3 is: 11111100
Negative values are indicated by a 1 in the high
order bit (MSB).
What is the problem with this
notation ? 31
One’s Complement
In one’s complement, perform the addition operation on the one’s
complement representation of the numbers
A situation called Overflow might occur when addition is
performed.
Overflow => the addition result exceeds the number of bits that was
fixed
When Overflow occurs. This value
(called “End-Around Carry” or EAC)
needs to be added to the rightmost bit.
Overflow occurred 
One’s Compliment‐ Example “End‐Around Carry” or
EAC
3
Example: Using one’s complement
binary arithmetic, find the sum of 48
and ‐ 19

We note that (19)10 one’s complement is


(00010011)2 , so -19 in one’s complement is:
11101100
(48)10 one’s complement is (00110000)2

(00011101)2 = (29)10
33
3‐ Two’s Complement
 To express a value in two’s complement:

oDecide the word / pattern length.


oIf the number is +ve, convert it to binary
oIf the number is ‐ve, find the one’s complement and then add 1.

 Example:
o In 8‐bit one’s complement, 3 is: 00000011

o‐3 in one’s complement is: 11111100

o‐3 in two’s complement form: 11111101


34
Two’s Complement ‐
Example
Obtain representation of two’s complement (6 bit)
for the following numbers
i) +710 ii) –1010
Solution: Solution:

(+7) = 0001112 (+10) 10 = 0010102


(same as sign-
magnitude) (-10) 10 = 1101012 + 12
= 1101102
Two’s Complement Addition
(Subtraction)
Addition operation in two’s complement is same with that of one’s complement,
i.e. overflow occurs if:
1. If both are negative numbers
2. If both have different signs and
|+ve Number| > |–ve Number|

BUT, you do the operation and ignore the EAC


Two’s Compliment – Example
2
With two’s complement arithmetic, all we do is add our two binary numbers.
Just discard any carries emitting from the high order bit.

– Example: Using
two’s complement
binary arithmetic,
find the sum of 48
and - 19.

38
Two’s complement Addition
(Subtraction)

1-37
What is the largest integer we
can store?
 Word size + signed or unsigned
 4‐bits word unsigned:

o0000, ….., 1111 = 16 values

oMax is number 15 = 24 ‐ 1
 4‐bits word signed magnitude:

oMin / Max numbers

‐8 / +7 =- 24‐1 / 24‐1 ‐ 1
What is the largest integer we
can store?
 Word size + signed or unsigned
 n‐bits word unsigned:
oMax number = 2n ‐ 1
 n‐bits word signed magnitude:
oMax/min number (2n‐1‐1) / -2n‐1
 32‐bits word unsigned / signed: 4294967295,  2147483647/8

You might also like