chapter 4: representation of data in computer systems: number ocr computing for gcse © hodder...

13
Chapter 4: Representation of data in computer systems: Number OCR Computing for GCSE © Hodder Education 2011

Upload: elmer-barber

Post on 02-Jan-2016

221 views

Category:

Documents


3 download

TRANSCRIPT

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

1000 100 10 1

Digit 1 2 3 4

Place value Digit Value

1000 1 1 × 1000 = 1000

100 2 + 2 × 100 = 200

10 3 + 3 × 10 = 30

1 4 + 4 × 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 2011

128 64 32 16 8 4 2 1

Each column is worth twice the column to it right.

128 64 32 16 8 4 2 1

0 0 0 0 0 0 1 0

Add up the columns that have a 1 on them. In this case it is 2.

128 64 32 16 8 4 2 1

1 0 0 0 1 1 1 1

In this case it is 128 + 8 + 4 + 2 + 1 = 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 10010011.

OCR Computing for GCSE © Hodder Education 2011

Result Remainder

147 ÷ 2 = 73 1

73 ÷ 2 = 36 1

36 ÷ 2 = 18 0

18 ÷ 2 = 9 0

9 ÷ 2 = 4 1

4 ÷ 2 = 2 0

2 ÷ 2 = 1 0

1 ÷ 2 = 0 1

Binary addition• The rules for binary addition:

• 0 + 0 = 0

• 0 + 1 = 1

• 1 + 1 = 0 carry 1

• 1 + 1 + 1 = 1 carry 1

• Add the binary equivalents of denary 4 + 5 (we know this equals 9).

OCR Computing for GCSE © Hodder Education 2011

Denary Binary

4 0 1 0 0

5 0 1 0 1

9 1 0 0 1

Carry 1

Binary addition• Sometimes we run into problems.

• Suppose we have eight bits in each location.

• Add the binary equivalent ofdenary 150 + 145.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

Denary Binary

150 1 0 0 1 0 1 1 0

145 1 0 0 1 0 0 0 1

295 0 0 1 0 0 1 1 1

Carry 1 1

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 2011

256 16 1

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

Result Remainder

141 ÷ 16 = 8 13

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.

• 64 + 15 = 79• So, 4F is 79 in denary.

OCR Computing for GCSE © Hodder Education 2011

Place value 256 16 1

Hex digits 0 4 F

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 1 1 1 1 0 0 1 1

Hex F 3

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

Hex D B

Denary 12 11

Binary 1 1 0 1 1 0 1 1

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