1 / 14

Lecture

Lecture. Signed Integer Representation. Sign and Magnitude One’s Complement Two’s Complement. Sign and Magnitude. Requires one bit to represent sign 0 for positive 1 for negative In 8 bit allocation you can only use 7 bits to represent absolute value of a number

preston
Télécharger la présentation

Lecture

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. Lecture

  2. Signed Integer Representation • Sign and Magnitude • One’s Complement • Two’s Complement

  3. Sign and Magnitude • Requires one bit to represent sign • 0 for positive • 1 for negative • In 8 bit allocation you can only use 7 bits to represent absolute value of a number • Range: - (2N -1) to + (2N -1) = -127 to +127

  4. Example • Store -258 in a 16 bit memory location using sign-and-magnitude representation • Solution: • First change the number to binary • 100000010 • Add 6 zeros to make a total of N-1 bits • 000000100000010 • Add an extra one on the left to show that the number is negative • 1000000100000010

  5. Representation of Zero in Sign and Magnitude Representation • Issue: Two representations of zero • +0  00000000 • -0  10000000

  6. One’s Complement • If the sign is positive no action is needed • If the sign is negative: • every bit is complemented • (changed from 0 to 1 or from 1 to 0) • The left most bit defines the sign of the number

  7. Example • Store -258 in a 16 bit memory location using one’s complement representation • Change the number to Binary • 100000010 • Add 7 zeros to the left so that there is a total of N(16) bits • 0000000100000010 • The sign is negative, so each bit is complemented • 1111111011111101

  8. Interpretation of One’s Complement • 1111111011111101 • If the left most bit is 0: • Change the entire number from binary to decimal • If the left most bit is 1 (Negative Number) • Complement all bits • 0000000100000010 • Convert to decimal • 258 • Add (-ve) sign in front of the number • (-258)

  9. Representation of Zero in One’s Complement • There are two representations of 0’s: • +0  00000000 • -0  11111111

  10. Two’s Complement • Twos’ complement is the most common, the most important and the most widely used representation of integers today • If sign is positive do nothing. • If the sign is negative: • Leave all the right most zeros and first 1 unchanged. • Complement the rest of the bits.

  11. Example • Store -40 in a 16 bit memory location using two’s complement representation • Change the number to binary: • 101000 • Add 10 zeros so that there are a total of N(16) bits • 0000000000101000 • The sign is negative so leave the right most zeros up to the first 1 (including the 1) unchanged and complement the rest: • 1111111111011000

  12. Interpretation of Two’s Complement • Interpretation of two’s complement • 1111111111011000 • If the left most bit is 0, change the whole number from binary to decimal and put a + sign • If the left most bit is 1 • Leave the right most bits up to the first 1 (inclusive) unchanged and complement the rest • 0000000000101000 • Change the whole number from binary to decimal • 40 • Put a – sign in front of the number • (-40)

  13. Summary of Integer representation

  14. Summary of Integer representation

More Related