Lect2 Number Representation
-
Upload
haneesha-muddasani -
Category
Documents
-
view
216 -
download
0
Transcript of Lect2 Number Representation
-
7/29/2019 Lect2 Number Representation
1/24
TA C162
LECTURE 2 REPRESENTATION OF BINARY NUMBERS
-
7/29/2019 Lect2 Number Representation
2/24
Todays Agenda
Binary Numbers
Non Positional
Positional
Signed Magnitude
1s Complement
Saturday, January 9, 2010 2Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
3/24
Representation of Information
One, Two, Three, .., Dozen, Gross
One + Two = Three
Dozen x Dozen = Gross
Problem:
Cumbersome when working with large Numbers
pera ons are no sys ema c
Saturday, January 9, 2010 3Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
4/24
Representation of Information
I, II, III, IV, V,, IX, X, XI,
X * X = C
XX * XX = CCCC
Problems
Operations are slightly better still not a good
Saturday, January 9, 2010 4Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
5/24
Representation of Information Simplest way
Unary Representation
Example 5 is represented as 11111
Problems
Cumbersome when working with large numbers
Saturday, January 9, 2010 5Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
6/24
Representation of Information Decimal Numbers
, , , , ,
Operations are systematic i.e. algorithmic
At the lowest level, a computer is an electronic machine.
Com uter is workin with devices which react topresence or absence of voltage (controlling the flow ofelectrons).
1. Presence of a voltage well call this state 1
2. Absence of a voltage well call this state 0
Saturday, January 9, 2010 6Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
7/24
Computer is a binary digital system
Di ital s stem:
Finite number of symbols
Binary (base two) system:
Has two states: 0 and 1
Saturday, January 9, 2010 7Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
8/24
Computer is a binary digital system Cont
Basic unit of information is the binary digit, or bit.
Values with more than two states re uire
multiple bits (wires). A se uence of two bits has four ossible states:
00, 01, 10, 11
A sequence of three bits has eight possible states:, , , , , , ,
Inference: A sequence ofn bits has 2n possible states.
Saturday, January 9, 2010 8Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
9/24
What kinds of data do we need torepresent? , , ,
point, complex, rational, irrational, , ,
Images pixels, colors, shapes,
oun
Logical true, false
Instructions
Saturday, January 9, 2010 9Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
10/24
Representation of a Number um er can e represente as Five
5
V 11111
A representation is a data type if there are operations in thecompu er a can opera e on n orma on enco e n a
representation
In this course we mainly use 2 data types 2s complement integers for representing +ve and ve integers
(to perform arithmetic operations)
co es or representng c aracters
Saturday, January 9, 2010 10Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
11/24
Unsigned Integers - No weightage for the position {0th, 1st, etc.. }
Problems?
We g te pos tona notaton
like decimal numbers: 329
3 is worth 300, because of its position, while 9 is only worth 9
329 101most
significantleast
significantmost
significantleast
significant
102 101 100 22 21 20
= =
Saturday, January 9, 2010 11Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
12/24
Unsigned Integers (cont.)An n-bit unsigned integer represents 2n values:from 0 to 2n-1.
22
21
20
0 0 0 0
0 1 0 2
0 1 1 3
1 0 0 4
1 0 1 5
1 1 0 61 1 1 7
Saturday, January 9, 2010 12Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
13/24
Unsigned Binary Arithmetic Base-2 addition just like base-10! Add from right to left, propagating carry
10010 10010 1111
carry
+ 1001 + 1011 + 1
11011 11101 10000
10111
11110
Saturday, January 9, 2010 13Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
14/24
Signed Integers With n bits, we have 2n distinct values. Assign about half to positive integers (1 through 2n-1 - 1)
- n-1 - -
That leaves two values: one for 0, and one extra
Positive integers
J ust like unsigned : zero in most significant (MS) bit00101 = 5
Ne ative inte ers
Set MS bit to show negative, other bits are the same as unsigned10101 = -5
MS bit indicates sign: 0=positive, 1=negative
Saturday, January 9, 2010 14Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
15/24
Question Given n bit string, What is the Maximum number we can representin Signed Magnitude form?
. . . . . .
2n-1 2n-2 . . . . . 22 21 20
The Maximum +ve value is : 2n-1 -1
The Maximum -ve value is : 2n-1
-1
Ex: Given 5 bits,
. - =Min. number in signed magnitude form is: -24 -1= -15
Saturday, January 9, 2010 15Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
16/24
How to represent Signed Integers
2s complement representation
Saturday, January 9, 2010 16Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
17/24
Representation of Signed Integers Cont
Ex: n = 3
Signed
magnitude
000 +0
010 +2
100 -0
101 -1
110 -2
111 -3
Saturday, January 9, 2010 17Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
18/24
Limitations! Problems with sign-magnitude representation!
Two representations of zero (+0 and 0)
complexity is more)Because:
How to add two sign-magnitude numbers?
e.g., try 2 + (-3)
10011
10101 => -5 ??
Saturday, January 9, 2010 18Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
19/24
1s Complement Representation Positive numbers representation is same as signed
integers.
Negative numbers represented by flipping all the bits ofcorresponding positive numbers
For Example:
+5 is re resented as 00101
-5 is represented by 11010
This representation was used in some early computers
Saturday, January 9, 2010 19Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
20/24
Question Given n bit string, What is the Maximum number we can representin 1s complement form?
he Maximum +ve value is : 2n-1 -1
The Maximum -ve value is : 2n-1 -1
Ex: Given 5 bits,
. - =
Min. number in signed magnitude form is: -24 -1= -15
Saturday, January 9, 2010 20Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
21/24
Representation of Signed Integers Cont
Ex: n = 3
Signed 1s
magnitude complement
000 + 0 + 0
010 + 2 + 2
100 0 3
101 1 2
110 2 1
111 3 0
Saturday, January 9, 2010 21Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
22/24
Example: 1s ComplementExample 1:How will we represent -12 in 1s complement form in 5 digits?
Step1: Take +12 in binary representation
Step2: Flip all the bits of the above
10011
Inference
-12 representation in 1s complement form: 10011
+12 representation in 1s complement form: 01100
Saturday, January 9, 2010 22Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
23/24
Representation of Signed IntegersEx: n = 4 Signed magnitude 1s Complement
0000 + 0 + 0
0001 + 1 + 1
0010 + 2 + 2
0011 + 3 + 3
0100 + 4 + 4
0101 + 5 + 5
0110 + 6 + 6
0111 + 7 + 7
1000 0 71001 1 6
1010 2 5
1011 3 4
1100 4 31101 5 2
1110 6 1
1111 7 0
Saturday, January 9, 2010 23Biju K Raveendran@BITS Pilani.
-
7/29/2019 Lect2 Number Representation
24/24
Limitations! Problems with sign-magnitude and 1s complement!
Two representations of zero (+0 and 0)
complexity is more)Because:
How to add two sign-magnitude numbers?
e.g., try 2 + (-3)
10011
10101 => -5 ??
How to add two ones complement numbers?
e. ., tr 4 + -3
Saturday, January 9, 2010 24Biju K Raveendran@BITS Pilani.