There are two types of binary integers used in computer prog
There are two types of binary integers used in computer programming languages: unsigned and signed. An unsigned (cardinal) binary integer has a range of 0 to 2n – 1, where n is the number of bits used. (A bit has a value of either 0 or 1.) Unsigned integers are stored in straight binary form in a computer. A signed integer has a range of -(2n - 1 ) to 2n - 1 – 1. In many applications it is important to know/specify which integer type you are using. Negative signed integers are stored in a 2\'s complement form in a computer. To convert an integer into its 2\'s complement, one must first convert the binary representation of a number into its 1\'s complement, which writes all 0s as 1s, and all 1s as 0s. The 2\'s compliment representation follows by adding a 1 to its 1\'s complement. For example, a 4-bit representation has an unsigned integer range of 0 to 24 – 1 = 16 – 1 = 15, and a signed integer range of -(23 ) = -8 to 23 – 1 = 8 – 1 = 7 because n = 4. 1) For the 4-bit unsigned integer, the standard binary algorithm applies with special cases being 0000 = 0 (minimum value) 1111 = 15 (maximum value) 0101 = 0 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 0 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 5 The first bit is not a sign bit in an unsigned integer. 2) For a signed integer, the first bit is reserved as a sign bit. For positive values, the binary algorithm applies to the remaining bits with 0 set as the first bit. For 4-bit signed integers: 0000 = 0 0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 (maximum value) To obtain their negative counterparts, convert them to their 1\'s complement form first, and then add 1 to change them into their 2\'s complement representation. 1110 (1\'s complement for 1) + 1 (add 1) 1111 = -1 (2\'s complement for 1) 1101 (1\'s complement for 2) + 1 (add 1) 1110 = -2 (2\'s complement for 2) 1100 (1\'s complement for 3) + 1 (add 1) 1101 = -3 (2\'s complement for 3) 1011 (1\'s complement for 4) + 1 (add 1) 1100 = -4 (2\'s complement for 4) 1010 (1\'s complement for 5) + 1 (add 1) 1011 = -5 (2\'s complement for 5) 1001 (1\'s complement for 6) + 1 (add 1) 1010 = -6 (2\'s complement for 6) 1000 (1\'s complement for 7) + 1 (add 1) 1001 = -7 (2\'s complement for 7) There is a binary number unaccounted for in the above construction. It is for the most negative value. For a 4-bit signed integer it is 1000 = -8 (minimum value) Notice that when you add the binary value for a positive number with its 2\'s complement you get all zeros, with a 1 carried over into the column just to the left of the sign bit; it is “thrown away”. In other words, when a positive integer is added to its 2\'s complement the result is 0. Also notice that whenever you take the 2\'s complement of a negative binary you retrieve its absolute value, with the exception of the minimum binary number, in our case it is 1000 whose 2\'s complement is 1000. (8 exceeds the range of this integer type.) Sign bits have the interpretation 0 + 1 i) What is the range of a 9-bit unsigned integer? ii) What is the range of a 9-bit signed integer? iii) What is the binary representation of decimal 125 as a 9-bit unsigned integer? iv) What is the binary representation of decimal 125 as a 9-bit signed integer? v) What is the binary representation of decimal -125 as a 9-bit signed integer? Return your answers to these six questions, and how you derived them, in a file named a2task5.pdf.
Task 5: Binary Integers (5 pts) There are two types of binary integers used in computer programming languages: unsigned and signed. An unsigned (cardinal) binary integer has a range of 0 to 2\" 1, where n is the number of bits used. (A bit has a value of either 0 or 1.) Unsigned integers are stored in straight binary form in a computer. A signed integer has a range of -(2n 2n 1-1. In many applications it is important to know/specify which integer type you are using. Negative signed integers are stored in a 2\'s complement form in a computer. To convert an integer into its 2\'s complement, one must first convert the binary representation of a number into its l\'s complement, which writes all 0s as ls, and all ls as 0s. The 2\'s compliment representation follows by adding a 1 to its l\'s complement. For example, a 4-bit representation has an unsigned integer range of 0 to 2 -1 16-1 15, signed integer range of -(2\')--8 1 because n 4. 1) For the 4-bit unsigned integer, the standard binary algorithm applies with special cases being 0000 0 (minimum value) 1111- 15 maximum value) 0101 0 x 23 1 x 2 0 x 2 1 x 2 0 x 8 1 x 4 0 x 2 1 x 1 3-5 The first bit is not a sign bit in an unsigned integer 2) For a signed integer, the first bit is reserved as a sign bit. For positive values, the binary algorithm applies to the remaining bits with 0 set as the first bit. For 4-bit signed integers 0000 0 0001 31 0010 32 0011 33 0100 4 0101 35 0110-6 0111- 7 (maximum value) To obtain their negative counterparts, convert them to their 1\'s complement form first, and then add 1 to change them into their 2\'s complement representation. 1110 (1\'s complement for 1) 1 (add 1) (2\'s complement for 1)Solution
1. What is the range of 9-bit unsigned integer?
For general \"k\" bits, we can have maximum of 2k possible values.
so for k=9 we will have 29 = 512 values
So for unsigned integer, we have values from 0 to 2k-1
So for 9 bits, we will have values like:
000000000 = 0 (min)
000000001 = 1
....
.....
.....
111111111 = 28 *1 + 27*1 + 26*1 + 25*1 + 24 *1 +23 *1 + 22*1 + 21 *1 +20 *1 = 511
So for case of unsigned integers, Maximum value is 511.
Range is from 0 - 511
2. What is the range of 9-bit signed integer?
Similarly, for \"k\" bits, we can have maximum of 2k possible values.
So for unsigned integer, we have values from - 2k -1 to 2k-1 -1
So for 9 bits, we will have values like:
000000000 = 0
000000001 = 1
.....
.....
011111111 = 255 maximum
100000000 = -256 minimum
100000001 = -255
.....
111111111 = -28 *1 + 27*1 + 26*1 + 25*1 + 24 *1 +23 *1 + 22*1 + 21 *1 +20 *1 = -1
(since left most bit represents the sign bit, so we add minus in left most bit )
So for case of unsigned integers, Maximum value is 511.
Range is -255 to 256
3. What is the binary representation of decimal 125 as 9-bit unsigned integer?
125 = 00111 1101
4. What is the binary representation of decimal -125 as 9-bit signed integer?
125 = 00111 1101
1\'s complement for 125 = 11000 0010
2\'s complement of 125 = 11000 0010
+ 1
------------------
-125 11000 0011

