SWEN-340: Data Representation - Homework 2 Instructions: 1. Assume all values are stored in the smallest variable size necessary for the value to fit. (I.E. 8 bit values are stored in a char and 16 bit values are stored in a short). (Signed value uses 2's complement format). 2. Provide hexadecimal values in 0x... format (C language format) 3. Edit this text file and record your answer. 4. Also for every answer show the manual steps required to arrive at you answer by editing this text file. 5. Submit your edited text file to the MyCourses assignment folder "Homework 1". All submissions MUST be text files. 6. All questions are worth one point Questions: 1. Convert decimal 95 to hexadecimal. Answer: Reasoning: 95 | 128 -- 0 95 | 64 -- 1 31 | 32 -- 0 31 | 16 -- 1 15 | 8 -- 1 7 | 4 -- 1 3 | 2 -- 1 1 | 1 -- 1 5 15 0x5F 2. Convert 0x1CD to unsigned decimal. (Hint: Convert it to binary first!) Answer: 461 Reasoning: 1 12 13 0001 1100 1101 1 * 1 0 * 2 1 * 4 1 * 8 0 * 16 0 * 32 1 * 64 1 * 128 + 1 * 256 --------- 461 3. What is the value of binary 10101011 in decimal if this is a negative number? Decimal Answer: -85 Reasoning: 01010100 # invert 01010101 # add 1 1 * 1 0 * 2 1 * 4 0 * 8 1 * 16 0 * 32 1 * 64 + 0 * 128 --------- -85 4. What is the value of binary 111001111 in decimal if this is an unsigned number? Decimal Answer: 463 Reasoning: 1 * 1 1 * 2 1 * 4 1 * 8 0 * 16 0 * 32 1 * 64 1 * 128 + 1 * 256 --------- 463 5. Add 0x8BCD and 0x02E6 (assume unsigned numbers): Hexadecimal Answer: 0x8EB3 Reasoning: 111 1 1 1 1000 1011 1100 1101 + 0000 0010 1110 0110 --------------------- 1000 1110 1011 0011 8 14 11 3 0x8EB3 6. Add 8 bit binary integers 10101111 and 11011011 Hexadecimal Answer: 0x8A Reasoning: 1111111 10101111 + 11011011 ---------- 10001010 8 10 8 A 7. How many bits are in each of the following data types? a. Byte Answer: 8 b. Short Answer: 16 c. Int Answer: 32 d. Long Answer: 32 e. Nibble Answer: 4