1 / 11

Two’s Complement

Two’s Complement. As an action: (Assume the starting value is 1011) Flip the bits from the starting value. 1011 => 0100 Add one to get the answer. 0100 + 1 => 0101. Signed Integer. MSB indicates sign: 0 is positive; 1is negative 1XXX XXXX 0XXX XXXX Two’s-Complement A – B = A + ( -B )

kenna
Download Presentation

Two’s Complement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two’s Complement As an action: (Assume the starting value is 1011) Flip the bits from the starting value. 1011 => 0100 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 )

  3. Two’s Complement/Signed Binary to Decimal As representation of a number 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 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.

  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 )

  6. Two’s-complement of Hexadecimal

  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 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 Convert the absolute value of the decimal to hexadecimal Represent +32 in binary (Assume the starting value is +32.) Absolute value of the decimal integer | +32 | = 32 Binary: 0010 0000 Hexadecimal: 2 0 If the decimal integer is negative, -32 Create two’s complement 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 If the hexadecimal is positive, retain the integer as is. Represent +20(Hexdecimal) in binary (Assume the starting value is +20 in hex.) Binary: 0010 0000 Decimal: 32 If the decimal integer is negative, -20 in hexadecimal Binary of -32 (decimal): 1110 0000 (see previous slide) Create two’s complement 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

More Related