1 / 6

Different representations to store integers

Different representations to store integers. Chapter 3. What is n ?. n = number of bits allocated to represent the integer. Representations to store integers. Unsigned integer. Sign-and-magnitude. Two’s complement. Unsigned integer representation. Range 0  2 n -1

rey
Download Presentation

Different representations to store integers

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. Different representationstostore integers Chapter 3

  2. What is n ? n = number of bits allocated to represent the integer

  3. Representations to store integers • Unsigned integer. • Sign-and-magnitude. • Two’s complement.

  4. Unsigned integer representation • Range 0  2n -1 • STEPS:to store decimal integer in an n-bits memory location using unsigned integer representation. - covert (……..)10  (……)2- if number of bits < n  add 0s to the left. • STEPS: to retrieve a binary number stored in memory as an unsigned integer. covert (……..)2  (……)10 • Overflow:occurs if the decimal is out of range. ( occurs if binary bits > n )

  5. Sign-and-magnitude representation • Range -( 2n-1 -1 )  +( 2n-1 -1 ) The leftmost bit defines the sign of the integer 0(+) , 1(-) • STEPS:to store decimal integer in an n-bits memory location using sign-and-magnitude representation . - store the sign in the leftmost bit.- covert (……..)10  (……)2 - use the remaining (n-1) bits to store the binary number. • STEPS: to retrieve a binary number stored in memory using sign-and-magnitude representation. - specify the sign from the leftmost bit.- the rest (n-1) bits is converted (……..)2  (……)10 • Overflow:occurs if the decimal is out of range.

  6. Two’s complement representation • Range -( 2n-1)  +( 2n-1 -1 ) The leftmost bit defines the sign of the integer 0(+) , 1(-) • STEPS:to store decimal integer in an n-bits memory location using two’s complement representation.- the integer is changed to n bit binary( covert (……..)10  (……)2 ).- if the decimal integer is 0 or +  the binaryis stored as it is. is -  take the two’s complement. • STEPS: to retrieve a binary number stored in memory in two’s complement representation.- if Leftmost = 1  apply the two’s complement. Leftmost = 0  no operation is applied.- convert (……..)2  (……)10 - add the sign. • Overflow:occurs if the decimal is out of range.

More Related