Chapter 4: Representation of data in computer systems: Number OCR Computing for GCSE © Hodder Education 2011
Denary Numbers can be expressed in many different ways. We usually use decimal or denary. Denary numbers are based on the number 10. We use ten digits: 0,1,2,3,4,5,6,7,8,9. When we put the digits together, each column is worth ten times the one to its right. OCR Computing for GCSE © Hodder Education 2011
Denary So, the denary number 1234 is OCR Computing for GCSE © Hodder Education 2011 Place value Digit1234 Place valueDigitValue × 1000 = × 100 = × 10 = × 1 =4 TotalΣ =1234
Binary to denary It is simpler to make machines that only need to distinguish two states, not ten. That is why computers use binary numbers. OCR Computing for GCSE © Hodder Education Each column is worth twice the column to it right Add up the columns that have a 1 on them. In this case it is In this case it is = 143.
Denary to binary One technique is to take the denary number and repeatedly divide by 2. Write down the result and the remainder. For example, find the denary number 147: Read from the bottom up: 147 in binary is OCR Computing for GCSE © Hodder Education 2011 ResultRemainder 147 ÷ 2 = ÷ 2 = ÷ 2 = ÷ 2 =90 9 ÷ 2 =41 4 ÷ 2 =20 2 ÷ 2 =10 1 ÷ 2 =01
Binary addition The rules for binary addition: = = = 0 carry = 1 carry 1 Add the binary equivalents of denary (we know this equals 9). OCR Computing for GCSE © Hodder Education 2011 DenaryBinary Carry1
Binary addition Sometimes we run into problems. Suppose we have eight bits in each location. Add the binary equivalent of denary We know this equals 295. No room for a carry so it is lost and we get the wrong answer. When there isn’t enough room for a result, this is called overflow and produces an overflow error. OCR Computing for GCSE © Hodder Education 2011 DenaryBinary Carry11
Hexadecimal numbers Programmers often write numbers down in hexadecimal (hex) form. Hexadecimal numbers are based on the number 16. They have 16 different digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Each column is worth16 times the one on its right. OCR Computing for GCSE © Hodder Education
Hexadecimal numbers We can convert denary numbers to hexadecimal by repeated division just as we did to get binary numbers. Take the denary number 141. We have the hexadecimal values 8 and 13 as remainders. 13 in hexadecimal is D. So, reading from the bottom again (where necessary), 141 in hexadecimal is 8D. OCR Computing for GCSE © Hodder Education 2011 ResultRemainder 141 ÷ 16 =813
Hexadecimal to denary All we do is multiply the numbers by their place values and add them together. For example, take the hexadecimal number 4F = 79 So, 4F is 79 in denary. OCR Computing for GCSE © Hodder Education 2011 Place value Hex digits04F Denary= 0 × 256= 4 × 16= 15 × 1 = 0= 64= 15
Binary to hexadecimal This is particularly easy. Simply take each group of four binary digits, starting from the right and translate into the equivalent hex number. OCR Computing for GCSE © Hodder Education 2011 Binary HexF3
Hexadecimal to binary Do the reverse. You may find it easier to go via denary. Treat each hex digit separately. OCR Computing for GCSE © Hodder Education 2011 HexDB Denary1211 Binary
Why use hexadecimal? Each hex digit represents four binary digits exactly. This makes it a useful shorthand way for programmers to write numbers. This saves effort and reduces the chance of making mistakes. OCR Computing for GCSE © Hodder Education 2011