CS-1104 Spring-2021 - Homework 4 Arjun Dua 26 March 2021 Positive Integers: - Smallest: 00000001 (1) - Largest: 01111111 (127) Negative Integers: - Largest: 11111111(-1) - Smallest: 10000000 (-128) Answer 1 As we can see above the range of numbers that can be stored is from -128 to 127. Answer 2 Using the following algorithm (in Python), we get the results def toBinary(x): if x < 0: x = 256+x if x != 0: remainder = x % 2 x = (x - remainder)/2 print (int(remainder)) toBinary(x) print(toBinary(int(input("Enter x =")))) 1. 127 = 01111111 1 2. 126 = 01111110 3. 1 = 00000001 4. 0 = 00000000 5. -1 = 11111111 6. -2 = 11111110 7. -127 = 10000001 8. -128 = 10000000 Answer 3 Generalizing the bit-range formula we used to find the range of 8 − bit storage to get the formula for an n − bit storage, we get xn−bit ∈ [−(2n−1 ), 2n−1 − 1] Therefore, • Range of 16 − bit computer is, from −32768 to 32767 • Range of 32 − bit computer is, from −2147483648 to 2147483647 • Range of 64 − bit computer is, from −9223372036854775808 to 9223372036854775807 Answer 4 Finding the binary of 49, using the the code block given above in answer 2, we get 4910 = 001000112 Switching 1’s and 0’s and then adding 1, we get 2’s complement of 49 = 11001111 Thus to find 55 + (−49), we do the following addition 2 00110111 + 11001111 00000110 Answer 5 Since only the first two digits are 1’s we just have to perform the following addition(one left shift), we get 00100110 + 001001100 01110010 In decimal form, this is a multiplication between 38 and 3 which gives us 114, which matches the binary answer. 3