**Introduction**

**Binary & Denary**

**Negative Numbers**

**Hexadecimal**

**Real Numbers**

Objectives

**Starters**

Storage locations in computers are built using electrical circuits

These can exist in one of two states - low voltage and high voltage

We replace these states with two symbols - 0 for low voltage and 1 for high voltage

This is known as a binary system

Digital computers use the binary system for storing instructions (programs) and data of all types

A binary digit, or bit, is a 0 or 1

A group of 8 bits is known as a byte

A group of bytes is known as a word

How many bytes make up a word depends on the type of computer. For example, a 64-bit machine has a word size of 64 bits = 8 bytes

**Data Representation**

Binary and Hexadecimal Numbers

Some key terms to remember

A number system that uses two digits,

0 and 1.

Binary

A binary digit; it can be 0 or 1

Bit

A group of 8 bits

Byte

Word

Denary number system

A group of bytes

A number system that uses the

digits 0 to 9

Let's remind ourselves

how the decimal or denary number system works.

It uses the 10 digits from 0 to 9.

Consider the number 146. These three digits represent one hundred, four tens and six ones.

100 10 1

1 4 6

As we move from right to left each digit is worth ten times as much as the previous one. This is known as base 10, the number base specifying how many digits are used and how much each digit is multiplied by as we move from right to left .

The binary system is a base 2 sytem, using only the digits 0 and 1

As we move from right to left, each digit is worth twice as much as the previous one. The place values are powers of 2.

The binary number 10010010 can be set out under place values as follows:

128 64 32 16 8 4 2 1

1 0 0 1 0 0 1 0

This represents 128 + 16 + 2 = 146.

Using only one byte to hold a number would limit the computer to storing only small numbers. Usually four or more consecutive bytes are used to store numbers

Converting from Binary to Denary

Put each binary digit under the correct heading in the table.

eg To translate 01001001 into decimal, arrange the digits in the table as follows

128 64 32 16 8 4 2 1

0 1 0 0 1 0 0 1

Add them up - 64+8+1 = 73

Activity

Convert the following

binary numbers to decimal

(a) 0100

(b) 0101

(c) 1010

(d) 01000010

(e) 01011001

(a) 4

(b) 5

(c) 10

(d) 66

(e) 89

Converting from Denary to Binary

To convert 21 from denary to binary, write down the place values

Then find the largest place value that is less than or equal to 21

That value is 16. Write a 1 in the column headed 16

Subtract 16 from 2

and you get 5

Now find the largest place value that is less than or equal to 5. It is 4.

Write a 1 in the column headed 4

Subtract 4 from 5

and you get 1.

Write a 1 in the column headed by 1

Fill in the empty

columns with 0

You end up with:

128 64 32 16 8 4 2 1

0 0 0 1 0 1 0 1

So 21 in binary is 00010101

Activity

1) Convert the number 227 to binary

2) Convert the following numbers to binary

a) 3 b) 9 c) 19

d) 28 e) 76 f) 129

1) Denary 227 is binary 11100011

2) a) 000 0011 b) 0000 1001

c) 0001 0011 d) 0001 1100

e) 0100 1100 f) 1000 0001

Binary Addition

Let's remind us how we add two denary numbers

When we add two digits which produce a result greater than 9, we use place values and carry a 1 to the next column on the left. Binary addition works in the same way

Here are the rules of binary

0 + 0 = 0 addition

0 + 1 = 1 + 0 = 1

1 + 1 = 1 (10 and carry 1)

1 + 1 + 1 = 11 (1 and carry 1)

Example

00011001 25

+ 00011010 + 26

00110011 51

Activity

1) a) Add 0101 and 0010

b) Add 01101010 and 01000011

c) Add 01010101 and 01111110

Check your results by converting to denary

2) Add 01010111 and 10101001

Comment on your results

Binary Multiplication

Let's remind ourselves how we multiply two numbers in denary.

If we want to multiply 7 by 4, we could interpret this as adding 7 four times

This is fine for small numbers, but how do we do multiplication with large numbers?

We use the place values of digits

Multiplying 7 by 10 gives 70

We have just moved the 7 into the next column on the left

Multiplying 7 by 100 gives 700;

We move the 7 two coumns to the left.

Binary multiplication works in the same way

Here are the rules of binary multiplication

0 x 0 = 0

0 x 1 = 1 x 0 = 0

1 x 1 = 1

1 x 10 = 10

If we want to multiply a binary number by 2 we move the binary pattern one place to the left and put a zero in the vacated binary place

If we want to multiply a binary number by 4, we move the binary pattern two places to the left and put a zero in each of the vacated binary places.

Let's do an

example

11000

x 10001

24

x 17

110000000

11000

Top number timesed by 1

Top number timesed by 10000

168

240

Top number timesed by 7

Top number timesed by 10

110000000

11000

110011000

168

240

408

Activity

Check that the rule is true by multiplying the following bit patterns by 2 and converting the numbers before and after multiplication to denary:

101 110 1001 10101 1100 1000

This causes bit overflow, an extra bit would be required to store the result.

101 multiplied by 2: 1010

In denary: 5 x 2 = 10

110 multiplied by 2: 1100

In denary: 6 x 2 = 12

1001 multiplied by 2: 10010

In denary 9 x 2 = 18

10101 multiplied by 2: 101010

In denary 21 x 2 = 42

1100 multiplied by 2: 11000

In denary 12 x 2 = 24

1000 multiplied by 2: 10000

In denary 8 x 2 = 16

a) Multiply 0101 and 0010

b) Multiply 01001010 and 00000011

c) Multiply 01000001 and 00000110

Check your results

Questions

1) What is the largest binary number that can be held in:

(a) 8 bits

(b) 16 bits

(c) 32 bits

(d) 64 bits

2) How many bits make on byte?

3) What are the possible values that one bit can take?

4) Convert the decimal numbers 20 and 10 into binary. Add the binary numbers for 20 and 10. Show your working. Then convert the result back into denary to check your answer

5) Convert the decimal numbers 5 and 6 into binary. Multiply the binary numbers for 5 and 6. Show your working. Then convert the result back to denary to check your answer.

Answers

1) What is the largest binary number that can be held in:

(a) 8 bits

(b) 16 bits

(c) 32 bits

(d) 64 bits

a) 11111111 = denary 255 =28 -1

b) 11111111 11111111 = denary 65,535 = 216 -1

c) 11111111 11111111 11111111 11111111 = 429,4967,295 = denary 232 -1

d) 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111

= denary 264 -1

2) How many bits make on byte?

8

3) What are the possible values that one bit can take?

0 or 1

4) Convert the decimal numbers 20 and 10 into binary. Add the binary numbers for 20 and 10. Show your working. Then convert the result back into denary to check your answer

5) Convert the decimal numbers 5 and 6 into binary. Multiply the binary numbers for 5 and 6. Show your working. Then convert the result back to denary to check your answer.

Two's Complement

Negative numbers can be represented using a system called

two's complement

Imagine the milometer of a car set at 00000

If the car goes forward one mile, the reading becomes 00001

If the milometer is turned back one mile, the reading becomes 99999 miles.

This could be interpreted as -1 mile

Key term to remember

Two's complement: A system for representing negative numbers

Worked Example

When we add the binary equivalents of 5 and -5, we obtain:

1011

+ 0101

(1)0000 We ignore the carry of 1

Notice that in two's complement representation if a number starts with a 1, it represents a negative number

Here is the procedure for converting a negative denary number to two's complement binary:

1 Find the binary value of the equivalent positive denary number

2 Change all the 0's to 1's and all the 1's to 0's

3 Add 1 to the result

And here is a method for changing the sign of a binary number:

1 Starting from the right, leave all the digits alone up to and including the first 1

2 Change all the other digits from 0 to 1 or from 1 to 0; for example -00101100 becomes 11010100

Activity

Convert the following to two's complement binary using 8 bits to represent your number

a) -5 b) -10 c) -20 d) 5

Converting a negative two's complement number to denary

Method 1

Flip the bits, add 1, then work out the denary equivalent

Method 2

Use the place values. Write the binary digits down under the place values 1,2,4,8,etc

Note that the leftmost bit has a negative place value. Add up all the place values which ahve a 1 under them.

Example

Convert the two's complement number 10011010 to denary

-128 64 32 16 8 4 2 1

1 0 0 1 1 0 1 0

This gives -128+16+8+2 = -102

Activity

Convert the following two's complement numbers to denary:

(a) 10101010 (b) 10000001

(c) 11111111 (d) 00010111

Binary Subtraction

The easiest way of performing binary subtraction is to convert the number to be subtracted to a negative number and then add it

Subtract 13 from 17 using 1 byte for each number

00001101 13

11110011 -13

00010001 + 17

00000100 4

Activity

1) Subtract 25 from 28 in binary and show your working

2) Subtract 23 from 123 in binary and show your working

Answers

a) 11111011 b) 11110110

c) 11101100 d) 00000101

Answers

a) -86 b) -127

c) -1 d) 23

Answer

25 is 00011001

so -25 is 11100111

28 is 00011100

00011100 28

11100111 -25

(1)00000011 3

Answer

23 is 00010111

so -23 is 11101001

123 is 01111011

01111011 123

11101001 -23

(1)01100100 100

The Most or Least Significant Bit

A positive number always has 0 as the most significant bit (MSB)

A negative number always has 1 as the most significant bit (MSB)

An even number always has 0 as the least significant bit (LSB)

An odd number always has 1 as the least significant bit (LSB)

-1 is represented by a 1 in every bit, whatever the word size

Questions

1. What is the largest negative number that can be held in 8 bits using two's complement?

2. Convert the decimal numbers 11 and 9 to binary. Using 8 bits for each number, show your working in binary of subtracting 9 from 11

3. Convert the decimal numbers 17 and 15 to binary. Using 8 bits for each number, show your working in binary of subtracting 17 from 15

4. Convert the decimal numbers 96 and 40 to binary. Using 8 bits for each number, show the binary pattern for -96 and -40. Commend on your result of adding these two patterns together

-128

00001001 in denary 9

11110111 -9

00001011 11

(1)00000010 2

00010001 in denary 17

11101111 -17

00001111 15

11111110 -2

Overflow!

10111111 -96

11011000 -40

(1)10010111 -136

01100000 in denary 96

10111111 in denary -96

00101000 in denary 40

11011000 in denary -40

Fixed-Point Binary Numbers

So far we have only been able to represent whole numbers

Calculations often have fractional results, do we need to be able to store real numbers

There are an infinate number of fractions...

...but there are only a limited number of bits to represent them.

Trying to map an infinite number of values onto a limited number of bit patterns results in a loss of precision.

We can easily extend the system we used for integers to include fractions. Look at the place values of denary numbers

100 10 1 . 1/10 1/100

0 6 8 . 2 5

The number 68.25 represents 6 tens, 8 ones, 2 tenths and 5 hundredths.

In binary the equivalent place values are...

126 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/6

The number 68.25 can be expressed as 68 + 1/4 andusing the place values converts to...

126 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/6

0 1 0 0 0 1 0 0 . 0 1 0 0

Notice the first digit after the point (known as the binary point) is worth one half. The equivalent in denary is worth one tenth. With the same number of digits after the point the binary system is less precise!

If we write down an amount in pounds sterling to 2 decimal places the amount is accurate to the nearest penny.

If we convert the amount to binary and allow only two digits after the binary point, we can hold .00 (0 pence), .01 (25 pence), .10 (50 pence) or .11 (75 pence) as the fractional part, so the amount is only accurate to the nearest 25 pence.

Fixed point notation assumes a binary point in a set position as there is no third symbol to store it explicitly.

Some decimal fractions

and their binary equivalents

Advantage

Disadvantage

Arithmetic is simple. It's the same as integer arithmetic. So processing is fast!

Of limited range. Increasing the number of bits after the binary points for precision decreases the range, and vice versa, in a fixed number of bits

There is an alternative, floating point numbers. This is covered in the A2 part of the course.

Questions

1. Using one byte to hold each number, with an imaginary binary point after the fourth digit, convert the following decimal numbers to binary.

a) 3.75 b) 5.1875

c) 7.562 d) 7.5627

2. Convert the following numbers to decimal, assuming 4 bits after the point.

i) 0000000001011000

ii) 0000000000110010

3. What is (i) the largest positive number and (ii) the smalles positive number that can be held in two bytes, assuming four bits after the point?

(ii) what is the difference between two consecutive values?

4. Using one byte to hold each number, with an imaginary binary point fixed after the fourth digit, (i) what is the largest number that can be stored?

(iii) How could the precision of storing a fractional number be improved? What effect would this have on the range of numbers that could be stored?

1. Using one byte to hold each number, with an imaginary binary point after the fourth digit, convert the following decimal numbers to binary.

a) 3.75 b) 5.1875

c) 7.562 d) 7.5627

2. Convert the following numbers to decimal, assuming 4 bits after the point.

i) 0000000001011000

ii) 0000000000110010

3. What is (i) the largest positive number and (ii) the smalles positive number that can be held in two bytes, assuming four bits after the point?

(ii) what is the difference between two consecutive values?

4. Using one byte to hold each number, with an imaginary binary point fixed after the fourth digit, (i) what is the largest number that can be stored?

(iii) How could the precision of storing a fractional number be improved? What effect would this have on the range of numbers that could be stored?

a) 0011.1100 b) 0101.0011

c) 0111.1001 (note: these are really the

d) 0111.1001 value 7.5625)

i) 5.5

ii) 3.125

i) 011111111111.1111

ii) 000000000000.0001

i) 0.111.1111 = denary 7.9375

ii) 0.0625

iii) Precision can be improved by using more bits after the binary point, but then the range of numbers is reduced for a given number of bits

Digital computers represent everything using the binary system, but binary patterns are very inconvenient for humans to read due to the size of them

Even a small number such as 254 requires eight digits to represent it in pure binary!

To make it easier for a human to read the contents of main memory or a computer file, the binary numbers are commonly put into groups of four bits

These are then displayed using the hexadecimal number system

The hexadecimal number system uses the digits 0 to 9 and the letters A to F. It is a shorthand notation for binary number patterns

Hexadecimal number are base-16

It is worth remembering that 1010 in binary is 10 in denary and A in hexadecimal. It's also worth remembering that 1111 is 15 in denary and F in hexadecimal. You can work out the rest as required

Let's convert decimal 213 to hex. First we convert it to binary

128 64 32 16 8 4 2 1

1 1 0 1 0 1 0 1

Divide the binary into groups of four starting from

the right

128 64 32 16 8 4 2 1

1 1 0 1 0 1 0 1

Now convert the groups into hexadecimal

1101 = 13 = D

0101 = 5 = 5

D5

Activity

Convert denary 126 into (a) binary and (b) hexadeximal

126 is 01111110 in

binary and 7E in hexadecimal

Converting from Hex to Decimal

Method 1: Convert each hex digit to its binary equivalent

A 3

8 4 2 1 8 4 2 1

1 0 1 0 0 0 1 1

128 64 32 16 8 4 2 1

1 0 1 0 0 0 1 1

So the hexadecimal number A3 equals 128+32+2+1 = 163 in denary

Method 2: Use the hexadecimal place values. To translate the hexadecimal number A3 to denary, do 10x16 + 3 = 160 +3 = 163 in denary

Activity

1. Convert the binary number 0110 1101 into (a) denary and (b) hexadecimal

2. Convert the following binary patterns into hexadecimal numbers: 1111 1110 1110 1101 1101 1010 1101. What is the message?

3. The following hexadecimal numbers represent 16-bit two's complement numbers: B13C, 7010, 1FFF, 8A1E, 9000, F73F. Can you tell which ones represent negative numbers? Convert them and check

4. Where have you seen hexadecimal numbers used? What were they used for?

B13C negative 1011 0001 0011 1100

7010 positive 0111 0000 0001 0000

1FFF positive 0001 1111 1111 1111

8A1E negative 1000 1010 0001 1110

9000 negative 1001 0000 0000 0000

F73F negative 1111 0111 0011 1111

If the first digit is greater than 7 then the number is negative

Examples: colour codes in paint software.

Memory dump, contents of memory locations.

0110 1101 is (a) 109 in denary and (b) 6D in hexadecimal

1111 1110 1110 1101

F E E D

1101 1010 1101

D A D

Starter 1

We are going to be numbers!

Three of you are going to be binary numbers

Four of your are going to be denary numbers

Denary numbers, you will stand up to show 9, lie down for 1, hide for 0, and be somewhere in-between for other digits.

Binary numbers, you will stand up to show 1, and sit to be 0

Familiarise yourself with these instructions

Everyone except the denary numbers sit with your back to the board. Get ready to write down what you think the numbers are.

Demonstrate 269

Demonstrate 504

Demonstrate 734

Everyone except the binary numbers sit with your back to the board. Get ready to write down what you think the numbers are.

Demonstrate 1001

Demonstrate 0110

Demonstrate 1101

What is the point?

Activity