Chapter 12: Computer arithmetic

OCR Computer Science for A Level Teaching and Learning Resources Chapter 12: Computer arithmetic ANSWERS TO QUESTIONS IN THE STUDENT’S BOOK Page 147 ...
Author: Norma Waters
7 downloads 0 Views 210KB Size
OCR Computer Science for A Level Teaching and Learning Resources

Chapter 12: Computer arithmetic ANSWERS TO QUESTIONS IN THE STUDENT’S BOOK Page 147 Question Complete the following binary additions and subtractions: 1. 10100110 + 110011 2. 1111 + 1001 3. 10010 – 1011 4. 10000 – 1111 5. 10101010 – 10111

Answer 1. 11011001 2. 11000 3. 111 4. 1 5. 10010011

Page 148 Question In the following questions, use two’s complement binary in eight bits and check your answers in denary. 1. 10011001 + 00111100 2. 11100011 + 01110010 3. Show the addition in two’s complement form of 58 + 73. 4. Show the subtraction in two’s complement form of 68 – 17. 5. Show the subtraction in two’s complement form of 55 – 63.

OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015

OCR Computer Science for A Level Teaching and Learning Resources Answer 1. 11010101 (–103 +60 = –43) 2. 00110011 (–29 + 114 = 85) 3.

4.

5.

58 73

00111010 01001001

17

10000011 = –125 00010001

1’s comp add 1

11101110 11101111

68 add 63

01000100 00110011 = 51 00111111

1’s comp add 1

11000000 11000001

55 add

00110111 11111000 = –8

Page 150 Question In all of these questions, the floating point numbers use a 10-bit two’s complement mantissa and 6-bit floating point exponent. Convert the following floating point numbers to denary: 1. 0101001000 000100 2. 0101100100 000110 3. 0111000000 111111 4. 1110010000 000011 5. 1100110000 000011

Answer 1. 10.25 2. 44.5 3. 0.4375 4. –1.75 5. –3.25

OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015

OCR Computer Science for A Level Teaching and Learning Resources Page 152 Question In the following questions, use normalised floating point representation with a two’s complement 10-bit mantissa and two’s complement 6-bit exponent. Represent the following denary values in normalised floating point form: 1. 123 2. 0.15625 3. –0.4375 4. –0.109375 What do you notice about the first two digits in normalised floating point numbers?

Answer 1. 0111101100 000111 2. 0101000000 111110 3. 1001000000 111111 4. 1001000000 111101 We can tell if a number is normalised because the first two digits will be different: 01 or 10.

Question 1. Subtract 10110 from 100000.

Answer 1010

Question 2. Add the binary values 01101101 and 11101110. Comment on the result.

Answer 101011011 (9 bits so overflows an 8-bit number)

Question 3. Demonstrate the process for two’s complement subtraction using the denary sums 77 – 63 and 56 – 72.

OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015

OCR Computer Science for A Level Teaching and Learning Resources Answer 63 1’s comp

00111111 11000000

add 1 77

11000001 01001101

add

(1) 00001110

72 1’s comp

01001000 10110111

add 1 56 add

10111000 00111000 11110000

Question 4. Convert the floating point number 1101110000 111011 to denary.

Answer –0.017578125

Question 5. In this question, using a floating point representation with a 4-bit two’s complement mantissa and a 4-bit two’s complement exponent, calculate: (a) the largest positive value that can be represented. (b) the minimum positive value that can be represented. (c) the largest magnitude negative number that can be represented. (d) the smallest magnitude negative number that can be represented.

Answer (a) largest positive is 0111 0111 or 896 in denary (7 × 27) (b) minimum positive value is 0001 1000 or 0.00390625 (1 × 2 – 8) (c) largest magnitude negative number is 1000 0111 or –1024 (–8 × 27) (d) smallest magnitude negative number is 1111 1000 or –0.00390625 (–1 × 2 – 8)

OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015

OCR Computer Science for A Level Teaching and Learning Resources Page 153 Question In the following questions, use normalised floating point representation with a two’s complement 10-bit mantissa and two’s complement 6-bit exponent. Check your answers in denary. 1. 0100100000 000100 + 0110100000 000011 2. 0110011000 001000 + 0111000000 000101 3. 0110000000 000011 – 0100100000 000010 4. 0100100000 000101 – 0110100000 000011 5. 1011000000 000010 – 0110000000 000001

Answer 1. 0111110000 000100 (9 + 6.5 = 15.5) 2. 0111010000 001000 (204 + 28 = 232) 3. 0111100000 000010 (6 – 2.25 = 3.75) 4. 0101110000 000100 (18 – 6.5 = 11.5) 5. 1000000000 000010 (–2.5 – 1.5 = –4)

Page 155 Question 1. For 01101011, mask this with 11001101 using AND, OR and XOR.

Answer Binary Mask AND OR XOR

0 1 0 1 1

1 1 1 1 0

1 0 0 1 1

0 0 0 0 0

1 1 1 1 0

0 1 0 1 1

1 0 0 1 1

1 1 1 1 0

Question 2. Create a mask to reverse the first four bits of a value, leaving the last four bits in their original state. State which logical operation is required.

Answer 00001111 with XOR.

Question 3. Identify the process using logical operators to create a two’s complement of a binary value.

Answer XOR with 11111111 and add 1.

Question 4. Identify the process using logical operators to normalise a floating point number. OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015

OCR Computer Science for A Level Teaching and Learning Resources Answer Mask with 01000… using AND to see if second digit is 1. Shift left 1 if not the case and repeat until it is.

Question 5. Interrupts from various sources are stored as bits in a binary value. How can logical operations be used to identify whether a specific interrupt has been generated?

Answer Mask the interrupt using AND and a mask with 1 in the appropriate place, 0s elsewhere.

Question 1. In the following questions, use normalised floating point representation with a two’s complement 10-bit mantissa and two’s complement 6-bit exponent. Check your answers in denary. (a) 0100011000 001000 + 0110100000 000110 (b) 1011000000 000011 – 0110000000 000101

Answer (a) 0110000000 001000 (140 + 52 = 192) (b) 1000110000 000101 (–5 – 24 = –29)

Question 2. Describe how bitwise operations can be used to normalise a floating point binary number.

Answer Mask with 01000… using AND to see if second digit is 1. Shift left 1 if not the case and repeat until it is.

OCR Computer Science for A Level Chapter 12

© Hodder & Stoughton Limited 2015