Professional Documents
Culture Documents
Today’s Agenda
Representation of Numbers
• Binary Numbers
• Unsigned Integers
Non Positional
Positional
• Signed Magnitude
• 1’s Complement
08/01/2009 1
TA C162 Computer Programming I
08/01/2009 3
TA C162 Computer Programming I
Inference:
• A sequence of n bits has 2n possible states.
08/01/2009 4
TA C162 Computer Programming I
08/01/2009 5
TA C162 Computer Programming I
Unsigned Integers
Non-positional notation
No weightage for the position {0th, 1st, …etc.. }
08/01/2009 6
TA C162 Computer Programming I
08/01/2009 7
TA C162 Computer Programming I
carry
10111
+ 111
11110
08/01/2009 8
TA C162 Computer Programming I
Signed Integers
With n bits, we have 2n distinct values.
• Assign about half to positive integers (1 through 2n-1)
and about half to negative (- 2n-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
08/01/2009 9
TA C162 Computer Programming I
Question
Given n bit string, What is the Maximum number we can
represent in Signed Magnitude form?
1 1 1 . . . . . . 1
2n-1 2n-2 . . . . . 22 21 20
08/01/2009 11
TA C162 Computer Programming I
For Example:
+5 is represented as 00101
-5 is represented by 11010
08/01/2009 12
TA C162 Computer Programming I
08/01/2009 13
TA C162 Computer Programming I
08/01/2009 14
TA C162 Computer Programming I
Limitations!
Problems with sign-magnitude and 1’s complement!
• Two representations of zero (+0 and –0)
• Arithmetic circuits are complex to implement above
representation
Because:
How to add two sign-magnitude numbers?
– e.g., try 2 + (-3)
00010
10011
10101 => -5 ??
08/01/2009 15