60 likes | 168 Vues
Explore different ways to store integers in computer memory, including unsigned integer representation, sign-and-magnitude, and two’s complement. Learn about ranges, steps to store and retrieve integers, and how overflow can occur.
E N D
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 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 )
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.
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.