Académique Documents
Professionnel Documents
Culture Documents
Todays Agenda
Representation of Binary Numbers
Unsigned, Signed Magnitude, 1s Compliment g g g p Done !!! 2s Complement
Base Conversion
Binary to Decimal and Decimal to Binary Decimal to Octal and Octal to Decimal Octal to Binary and Binary to Octal Binary to Hexadecimal and Hexadecimal to Binary
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
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
1s complement +0 +1 +2 +3 3 2 1 0
7
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
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Tuesday, January 12, 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
9
Because:
How to add two sign-magnitude numbers?
e.g., try 2 + (-3) 00010 10011 10101 => -5 ??
A Good Representation
Should keep the logic circuits simple Representation of Negative Numbers should make Arithmetic & Logic Unit (ALU) simple Addition of an arbitrary integer with same magnitude but opposite sign should return 0
This can be accomplished by 2s complement representation. 2s representation A + (-A) = 0 From (2n-1-1) to +(2n-1-1) ALU adds 1 to successive representations
11
12
Example
Represent -12 in 2s complement form (5 digits)
Step 1:Represent +12 in binary 01100 Step 2: Find 1s complement of that 10011 Step 3: Add 00001 to 1s complement 10100 Result (-12 in 2s complement form) is 10100
Tuesday, January 12, 2010 Biju K Raveendran@BITS Pilani. 13
011010000
(1 s (1s comp) (flip) (copy)
100110000
14
Advantage of 2s complement
Twos complement representation developed to make circuits easy for arithmetic.
For each positive number (X), assign value to its negative (-X) (X) ( X), such that X + (-X) = 0 with normal addition, ignoring carry out
15
Example: p
2+(-3) =?? (in 5 digits) p p Express -3 in 2s complement form: +3 1s Complement of 3 2s Complement of 3 2 C l t f +2 + -3 Look at MSB 00011 11100 11101 i -3 i.e. 3 00010 + 11101 11111 1 So take 2s complement again 00001
16
What is Base?
Decimal Number System
Base is 10 All numbers are represented by 0 to 9
Inference
Maximum digit value in any number system is Base -1 1
Tuesday, January 12, 2010 Biju K Raveendran@BITS Pilani. 18
Add powers of 2 that have 1 in the 8 256 corresponding bit positions positions. 9 512 If original number was negative, affix a minus 10 1024 sign in front. Assuming 8 bit 2 complement numbers. A i 8-bit 2s l t b
Tuesday, January 12, 2010 Biju K Raveendran@BITS Pilani. 19
More Examples
X = 00100111two = 25+22+21+20 = 32 4 2 1 2 2 2 32+4+2+1 X = 39ten X = 11100110two -X = 00011010 X = 24+23+21 = 16+8+2 = 26ten X = -26ten
Assuming 8-bit 2s complement numbers.
Tuesday, January 12, 2010 Biju K Raveendran@BITS Pilani. 21
n 2n
0 1 2 3 4 5 6 7 8 9 10 1 2 4 8 16 32 64 128 256 512 1024
Examples
X=11000111t two X=10001100two
22
Algorithm
Consider a Number N (5-bit 2s complement) (5 bit 2 s Step 1:
Obtain the binary representation of magnitude of N
Step 2:
If N is positive, the current representation is final positive If N is negative, then form negative of this 2s complement representation
23