1 / 19

Representing Strings

Representing Strings. ASCII (or UNICODE) characters linear sequences of characters, terminated by special character code (0). Representing Numbers. Integers Positive values Negative values Rationals Reals. Representing Integers Unsigned integers.

jola
Télécharger la présentation

Representing Strings

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. Representing Strings • ASCII (or UNICODE) characters • linear sequences of characters, terminated by special character code (0) Ch.4 - Computer Arithmetic

  2. Representing Numbers • Integers • Positive values • Negative values • Rationals • Reals Ch.4 - Computer Arithmetic

  3. Representing IntegersUnsigned integers 0000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0000 0000 0000 0000 0000 0000 0000 0001two = 1ten 0000 0000 0000 0000 0000 0000 0000 0010two = 2ten … 1111 1111 1111 1111 1111 1111 1111 1111two = 4,294,967,295ten Ch.4 - Computer Arithmetic

  4. Representing IntegersAddition of positive values 0001two = 1ten 1111two = 15ten + 0110two = 6ten + 0011two = 3ten 0111two = 7ten 0010two = 2ten (overflow!) But what about subtraction? Ch.4 - Computer Arithmetic

  5. Representing IntegersSubtraction of positive values 0111two = 7ten 0111two = 7ten - 0001two = 1ten + ????two = -1ten 0110two = 6ten 0110two = 6ten Ch.4 - Computer Arithmetic

  6. Representing IntegersSign bit and magnitude 0 000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0 000 0000 0000 0000 0000 0000 0000 0001two = 1ten 0 000 0000 0000 0000 0000 0000 0000 0010two = 2ten … 0 111 1111 1111 1111 1111 1111 1111 1111two = 2,147,483,647ten 1 111 1111 1111 1111 1111 1111 1111 1111two = -2,147,483,647ten … 1 000 0000 0000 0000 0000 0000 0000 0001two = -1ten 1 000 0000 0000 0000 0000 0000 0000 0000two = -0ten Ch.4 - Computer Arithmetic

  7. Representing IntegersSubtraction -Sign bit and magnitude 0 111two = 7ten 0 111two = 7ten - 0 001two = 1ten + 1 001two = -1ten 0 110two = 6ten 0 110two = 6ten Complicated logic required Ch.4 - Computer Arithmetic

  8. Representing IntegersSigned -One’s Complement • If x is positive, convert x to binary • If x is negative • Write the positive value of x in binary • Reverse each bit Ch.4 - Computer Arithmetic

  9. Representing IntegersSigned -One’s Complement 0000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0000 0000 0000 0000 0000 0000 0000 0001two = 1ten 0000 0000 0000 0000 0000 0000 0000 0010two = 2ten … 0111 1111 1111 1111 1111 1111 1111 1111two = 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0000two = -2,147,483,647ten … 1111 1111 1111 1111 1111 1111 1111 1110two = -1ten 1111 1111 1111 1111 1111 1111 1111 1111two = -0ten Ch.4 - Computer Arithmetic

  10. Representing IntegersSubtraction -One’s Complement 0111two = 7ten 0111two = 7ten - 0001two = 1ten +1110two = -1ten 0110two = 6ten 0110two = 6ten Alas 0111two + 1110two = 0111two ! Ch.4 - Computer Arithmetic

  11. Representing IntegersSigned -Two’s Complement 0000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0000 0000 0000 0000 0000 0000 0000 0001two = 1ten 0000 0000 0000 0000 0000 0000 0000 0010two = 2ten … 0111 1111 1111 1111 1111 1111 1111 1111two = 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0000two = -2,147,483,648ten … 1111 1111 1111 1111 1111 1111 1111 1110two = -2ten 1111 1111 1111 1111 1111 1111 1111 1111two = -1ten Ch.4 - Computer Arithmetic

  12. Representing IntegersSigned -Two’s Complement • If x is positive, convert x to binary • If x is negative • Write the positive value of x in binary • Reverse each bit • Add 1 to the result Ch.4 - Computer Arithmetic

  13. Representing IntegersSubtraction -Two’s Complement 0111two = 7ten 0111two = 7ten - 0001two = 1ten +1111two = -1ten 0110two = 6ten 0110two = 6ten Ch.4 - Computer Arithmetic

  14. Representing IntegersSigned and Unsigned • Need both signed (2’s complement) and unsigned (always positive) integer values • Integers are also memory addresses • and addresses are never negative Ch.4 - Computer Arithmetic

  15. MIPS Instructions (Arithmetic)(so far…) Ch.4 - Computer Arithmetic

  16. MIPS Instructions (Cond. Branch)(so far…) Ch.4 - Computer Arithmetic

  17. Representing IntegersSigned -Two’s Complement Negating values • Reverse each bit • Add 1 to the result Ch.4 - Computer Arithmetic

  18. Representing IntegersSigned -Two’s Complement Sign Extension Converting an n-bit binary number to a longer m-bit number • Take most significant bit (nth bit from right) and duplicate it in the m-n new bits Ch.4 - Computer Arithmetic

  19. Representing IntegersSigned -Two’s Complement Detecting Overflow When result cannot fit in representation Ch.4 - Computer Arithmetic

More Related