Download presentation
Presentation is loading. Please wait.
Published byMalcolm Bridges Modified over 9 years ago
1
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value. 1011 => 0100 2.Add one to get the answer. 0100 + 1 => 0101
2
Signed Integer MSB indicates sign: 0 is positive; 1is negative 1XXX XXXX 0XXX XXXX Two’s-Complement A – B = A + ( -B ) 1 – 1 = 1 + ( -1 ) Starting Value 0000 0001 (+1 in decimal) Step 1: Reverse the bits 1111 1110 Step 2: Add 1 to the value from step 1 +0000 0001 Sum:Two’s-complement representation 1111 1111 (-1 in decimal) 1 0000 0001 1111 1111 1 + ( -1 )(1)0000 0000
3
Two’s Complement/Signed Binary to Decimal 1.As representation of a number 1.If MSB, the left most bit, is a 0, you can convert it to decimals as if it were an unsigned binary integer. (The number represented is simply the bits’ value as a base 2 number.) This is positive or zero. 00010000 => 16 (decimal) 0101 => 5 (decimal) 0000 => 0 (deciml) (0000=>1111=>1111 + 1=>0000=>0; NOT 10000; the extra 1 does not fit in the available four bits)
4
Two’s Complement/Signed Binary to Decimal 2.As representation of a number If MSB, the left most bit, is a 1, the number represented is negative. To find its magnitude, we take the two’s complement of the bits (flip them and add 1) and interpret the result as a base 2 number. Because the original integer is negative, we add “-”, negative sign, to its decimal value. Starting value1110 Step 1: Reverse the bits0001 Step 2: Add 1 to the value from Step 1 1 Step 3: Create the two’s complement0010 Step 4: Convert to decimal 2 Step 5: Since the original value is negative, report its negation. -2
5
Signed Integer MSB indicates sign: 0 is positive; 1is negative 1XXX XXXX 0XXX XXXX Two’s-Complement A – B = A + ( -B ) 1 – 1 = 1 + ( -1 ) Starting Value 0000 0001 (+1 in decimal) Step 1: Reverse the bits 1111 1110 Step 2: Add 1 to the value from step 1 +0000 0001 Sum:Two’s-complement representation 1111 1111 (-1 in decimal) 1 0000 0001 1111 1111 1 + ( -1 )(1)0000 0000
6
Two’s-complement of Hexadecimal Hexadecimal starting value 6 A 3 D Binary Bits 0110 1010 0011 1110 Step1: Reverse the bits 1001 0101 1100 0001 Step2: Add 1 to the value from Step 1 0000 0000 0000 0001 Sum: Two’s-complement 1001 0101 1100 0010 Two’s-complement of Hexadecimal 9 5 C 3 Hexadecimal starting value 9 5 C 3 Binary Bits 1001 0101 1100 0010 Step1: Reverse the bits 0110 1010 0011 1101 Step2: Add 1 to the value from Step 1 0000 0000 0000 0001 Sum: Two’s-complement 0110 1010 0011 1110 Two’s-complement of Hexadecimal 6 A 3 D
7
Signed Integer +10(decimal): 00001010 Reverse the bits: 11110101 Add 1: +00000001 ------------------------------ 11110110 -10(decimal): 11110110 10-10=10+(-10) 00001010 (10) +11110110 (-10) ---------------------------- (1)00000000 (0)
8
Signed Decimal to Binary 1.Convert the absolute value of the decimal to binary For example, 43 and -43 in decimal Represent 43 in binary Absolute value of the decimal integer | 43| = 43 Binary: 0010 1011 2. If the decimal integer is negative, (Assume the starting value is -43) Absolute value of the decimal integer | -43| = 43 Binary: 0010 1011 Create two’s complement 0010 1011 => 1101 0100=> +1 =>1101 0101
9
Signed Decimal to Hexadecimal 1.Convert the absolute value of the decimal to hexadecimal 2.Represent +32 in binary (Assume the starting value is +32.) Absolute value of the decimal integer | +32 | = 32 Binary: 0010 0000 Hexadecimal: 2 0 3.If the decimal integer is negative, -32 4.Create two’s complement 5.0010 0000 => 1101 1111=> +1 =>1110 0000 (E0) Reverse the bits, 1101 1111 Add 1, 11100000 Represent the resulting binary in hex, E0
10
Signed Hexadecimal to Decimal 1.If the hexadecimal is positive, retain the integer as is. 2.Represent +20(Hexdecimal) in binary (Assume the starting value is +20 in hex.) Binary: 0010 0000 Decimal: 32 3.If the decimal integer is negative, -20 in hexadecimal 4.Binary of -32 (decimal): 1110 0000 (see previous slide) 5.Create two’s complement 6.1110 0000=> 0001 1111=> +1 =>0010 0000 (E0) Reverse the bits, => 0001 1111 Add 1, =>00100000 Decimal: 32 Attach a minus sign to the beginning of the decimal integer, -32.
11
Ranges of Integer Values TypeMinimum and Maximum unsigned short0 to 65535 signed short–32768 to 32767 unsigned long0 to 4294967295 signed long–2147483648 to 2147483647
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.