1 / 10

Understanding Signed Integers and Two's Complement Representation

This document delves into the concepts of signed integers and two's complement representation, essential for computer architecture. It explains how to compute the two's complement of a binary number by flipping its bits and adding one. The text also covers the conversion from binary to decimal for two's complement integers, detailing the significance of the leading bit in determining the sign. Finally, it provides a method for converting decimal numbers into their two's complement binary forms, illustrating with examples and operations for both positive and negative integers.

Télécharger la présentation

Understanding Signed Integers and Two's Complement Representation

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. 1 Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610

  2. Signed Integers • Thus, for simplicity of hardware we use the two’s complement representation • How do we compute two’s complement? • Write the magnitude of the number in binary • Compute the one’s complement, that is flip the bits • Add one to the result

  3. Signed Integers • How do we reverse two’s complement? • We apply it again! • That is two’s complement(two’s complement(N)) = N

  4. Signed Integers • If the following 6 bits number is in two’s complement form, what is the number? (101001)2 Compute one’s complement: (010110)2 Add one: (010111)2 = (23)10 • Thus, the number is -23

  5. Binary to Decimal Conversion • We now systematically look at convert from binary to decimal for two’s complement stored integers • We assume the binary number is in the form M=(bn bn-1 … b2 b1 b0)2 where bi is either 0 or 1.

  6. Binary to Decimal Conversion • Consider the leading bit bn. If it is zero, the integer is positive or zero. If it is one, the integer is negative. • If bn=1, then compute the two’s complement of bn-1…b1b0. Then bn-1x2n-1 + … + b2x22 + b1x21 + b0x20 is the magnitude of the value • If the leading bit bn was 1, then add the negative sign.

  7. Binary to Decimal Conversion • Convert the following two’s complement representations to their decimal values: • 1100 0011 • 0011 0110 • 1111 1110

  8. Decimal to Binary Conversion • Take the magnitude of the decimal number • Convert the magnitude of the number to binary form • If the number is negative, compute the two’s complement of the number

  9. Review of Unsigned Integers • To convert from positive decimal number M to binary: • Set x=M, k=0 • Compute x÷2 = y R bk • Set x=y, k=k+1 • Go to 2 if x≠0 and repeat • The bits are the remainders listed right to left …b3b2b1b0

  10. Decimal to Binary Conversion • Convert the following decimal numbers to their two’s complement forms for 8 bits: • 45 • -34 • -2 • 0

More Related