Download Memory & Storage: Lesson 5 Storing Numbers and more Slides Computer science in PDF only on Docsity! Memory & Storage: Lesson 5 Storing Numbers Starter 1. What is 7 in binary? 2. What is 1001 in denary? Memory & Storage: Lesson 5 Storing Numbers Learning Outcomes: 1. Convert positive denary whole numbers (0-255) into 2-digit hexadecimal numbers and vice versa 2. Convert between binary, denary and hexadecimal equivalents of the same number 3. Add two 8-bit binary integers and explain overflow errors which may occur 4. Understand the use of binary shifts Memory & Storage: Lesson 5 Storing Numbers Memory & Storage: Lesson 5 Storing Numbers Denary to hex conversion 1) Divide the denary number by 16 to get the number of 16s (the left-hand hex digit) 2) The remainder gives you the units Denary 18 becomes: 18 / 16 = 1 remained 2 so the hex value for 18 is 1 2 (Spoken, ‘One Two’, not ‘Twelve’) • What is denary 27 in hex? • What is denary 44 in hex? Memory & Storage: Lesson 5 Storing Numbers Answers: Conversions • What is hex 27 in denary? • 2 x 16 + 7 = 39 • What is denary 27 in hex? • 27/16 = 1 remainder 11 • Hex value of 1 = 1 • Hex value of remainder 11 is B in hex = 1B • What is denary 44 in hex? • 44/16= 2 remainder 12 • Hex value of 2 = 2 • Hex value of remainder 12 is C in hex = 2C Memory & Storage: Lesson 5 Storing Numbers Binary to hex conversion 1. Take a binary word of 8 bits 1 1 1 0 0 1 0 1 2. Divide into two nibbles of 4 bits 1 1 1 0 0 1 0 1 3. Convert each nibble into its hex value and re-join 1 1 1 0 = 14 = E in Hex + 0 1 0 1 = 5 in Hex So 1 1 1 0 0 1 0 1 = E5 in Hex Memory & Storage: Lesson 5 Storing Numbers Why use hex? • There are advantages for programmers and Computer Scientists in using hex rather than binary • It is much simpler to remember a hex value than a binary value • It is quicker to write or type since a hex digit only takes up one digit rather than 4 bits • People are less likely to make an error with fewer digits • It is easy to convert between hex and binary Memory & Storage: Lesson 5 Storing Numbers Task 1: Hexadecimal Complete Task 1 on the worksheet Navigation: � Student G-Suite � Computer Studies � GCSE Computer Science � Unit 1: Computer Systems � 1.2: Memory & Storage � Lesson 5: Storing Numbers � Worksheet 1 Memory & Storage: Lesson 5 Storing Numbers • Worksheet 2 • Complete Task 1b on Worksheet 2 • CGP book: Questions page 79-80 • Finished? • S:\ICT\GCSE\Computer Science\Theory\Paper 2\2.4- Data Representation\Lesson 2- Numbers\ • 2.6 Lesson 2 Binary-Denary conversion questions • 2.6 Lesson 3 Binary- Hexadecimal conversion questions Memory & Storage: Lesson 5 Storing Numbers The rules of binary addition Work right to left and apply these simple rules: 1. 0 + 0 = 0 2. 0 + 1 = 1 3. 1 + 0 = 1 4. 1 + 1 = 0 Carry 1 5. 1 + 1 + 1 = 1 Carry 1 1 1 1 0 1 1 0 0 1 0 1 0 + =1 14 12 26 11 R u le 1R u le 2 o r 3R u le 4R u le 5C a rr y B it Memory & Storage: Lesson 5 Storing Numbers Adding binary values 0 1 0 1 1 1 1 1 1 0 0 + = 1 1 1 1 1 Carry Memory & Storage: Lesson 5 Storing Numbers Adding numbers • Computers work with a fixed number of bits at a time • This can cause problems • What problem will arise when adding the following bytes and storing the result in one byte? 1 1 1 1 0 0 0 0 + 1 0 0 1 1 1 1 1 Memory & Storage: Lesson 5 Storing Numbers Logical binary shift operations • A binary shift left of one bit moves all the bits one place to the left • The vacant bit spaces are filled with zeros • Looking at the table above, what effect does a shift left of one place have on the binary value? What effect would a shift right of two places have? 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 Memory & Storage: Lesson 5 Storing Numbers Shift operations • A binary shift left of one bit doubles the number • E.g. 1000=8 Shift left once, 10000=16 • A binary shift right of two places results in halving the number and rounding down each time • Example 1: 1000=8 Right shift once, 100 = 4 Right shift again, 10 = 2 • Example 2: 1001 = 9 Right shift once, 100 = 4 Right shift again, 10 = 2 Memory & Storage: Lesson 5 Storing Numbers Effects of shifts • Logical shifts can very quickly multiply or divide a binary number by a factor of two • Left shifts multiply • Right shifts divide • A loss of accuracy can occur if 1 bits are removed: • 22 / 4 is not exactly 5 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 1