Professional Documents
Culture Documents
Lect2 Number Representation
Lect2 Number Representation
Todays Agenda
Representation of Numbers
Binary Numbers Unsigned Integers
Non Positional Positional
Representation of Information
Representation 1
One, Two, Three, .., Dozen, Gross Operation:
One + Two = Three Dozen x Dozen = Gross
Problem:
Cumbersome when working with large Numbers Operations are not systematic O ti t t ti
Representation of Information
Second Attempt
I, II, III, IV, V,, IX, X, XI, Operations
X*X=C XX * XX = CCCC
Problems
Operations are slightly better still not a good representation
Representation of Information
Simplest way
Unary Representation Example 5 is represented as 11111
Problems
Cumbersome when working with large numbers
Representation of Information
Decimal Numbers
1, 2, 1 2 , 10 11 10,11, Operations are systematic i.e. algorithmic Problem:
At the lowest level, a computer is an electronic machine. Computer is working with devices which react to p g presence or absence of voltage (controlling the flow of electrons).
Presence of a voltage well call this state 1 Absence of a voltage well call this state 0
Inference:
A sequence of n bits has 2n possible states.
Saturday, January 9, 2010 Biju K Raveendran@BITS Pilani. 8
Representation of a Number
Number N b 5 can b represented as be t d
Five 5 V 11111 0101 A representation is a data type if there are operations in the computer that can operate on information encoded in that t th t t i f ti d d i th t representation In this course we mainly use 2 data types
2s complement integers for representing +ve and ve integers (to perform arithmetic operations) ASCII codes f representing characters d for ti h t
Saturday, January 9, 2010 Biju K Raveendran@BITS Pilani. 10
Unsigned Integers
Could represent a number (5) with a string of ones (11111) (5) ( 11111 ) Problems?
Weighted W i ht d positional notation iti l t ti
like decimal numbers: 329 3 is worth 300, because of its position, while 9 is only worth 9
most significant least significant most significant least significant
329
101
21
22
20
12
1111 + 1 10000
13
Signed Integers
With n bits, we have 2n distinct values.
Assign about half to positive integers (1 through 2n-1 - 1) and about half to negative (- 2n-1 - 1 through -1) That leaves two values: one for 0, and one extra
Positive integers
Just like unsigned : zero in most significant (MS) bit 00101 = 5
Negative integers
Set MS bit to show negative, other bits are the same as unsigned 10101 = -5
Inference
MS bit indicates sign: 0=positive, 1=negative
14
Question
Given n bit string, What is the Maximum number we can represent in Signed Magnitude form? 1
2n-1
1
2n-2
1 .
. .
. .
. .
. .
.
22
.
21
1
20
The Maximum +ve value is : 2n-1 -1 The Maximum -ve value is : 2n-1 -1 Ex: Given 5 bits, Max. Max number in signed magnitude form is: 24 -1 =15 1 15 Min. number in signed magnitude form is: -24 -1= -15
15
16
Limitations!
Problems with sign-magnitude representation!
Two representations of zero (+0 and 0) Arithmetic circuits are complex to implement (hardware complexity is more)
Because:
How to add two sign-magnitude numbers?
e.g., try 2 + (-3) 00010 10011 10101 => -5 ??
18
1s Complement Representation
Positive numbers representation is same as signed integers. Negative numbers represented by flipping all the bits of corresponding positive numbers For Example: +5 is represented as 00101 p -5 is represented by 11010 This representation was used in some early computers
19
Question
Given n bit string, What is the Maximum number we can represent in 1s complement form? The Maximum +ve value is : 2n-1 -1 The Maximum -ve value is : 2n-1 -1 Ex: Given 5 bits, Max. Max number in signed magnitude form is: 24 -1 =15 1 Min. number in signed magnitude form is: -24 -1= -15
20
1s complement +0 +1 +2 +3 3 2 1 0
21
Example: 1s Complement p p
Example 1: How will we represent -12 in 1s complement form in 5 digits? Step1: Take +12 in binary representation 01100 Step2: Flip all the bits of the above 10011 Inference -12 representation in 1s complement form: 10011 +12 representation in 1s complement form: 01100
22
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Saturday, January 9, 2010
+0 +1 +2 +3 +4 +5 +6 +7 0 1 2 3 4 5 6 7
Biju K Raveendran@BITS Pilani.
+0 +1 +2 +3 +4 +5 +6 +7 7 6 5 4 3 2 1 0
23
Limitations!
Problems with sign-magnitude and 1s complement!
Two representations of zero (+0 and 0) Arithmetic circuits are complex to implement (hardware complexity is more)
Because:
How to add two sign-magnitude numbers?
e.g., try 2 + (-3) 00010 10011 10101 => -5 ??