1.2 Memory and Storage

How do we count?

This seems a very obvious question, but we need to think about it in a bit more detail before we can start to look at how computers count.

We count in 10s. This is probably because we conveniently have ten digits on our hands! Because we count in 10s we need ten symbols to represent the ten values, so we have the numbers 0,1,2,3,4,5,6,7,8 and 9. When we count upwards, we move on to the next digit until we get to 9. When we get to 9, we start again at 0, but add one onto the next left column, so after 9 we get 10.

Computers don't use ten digits (or denary, also called base 10). They run using electrical components called transistors which can be either turned on, or turned off. We need a system that can represent these two values and conveniently we can use binary, or base two. Binary only has two digits, a 0 and a 1.

To count in binary, we do exactly the same thing that we would have done in denary. We move up through the symbols until we get to the top (this time, its 1), then add 1 to the next left hand column. This gives us the numbers that you see on this diagram.

In denary the column headings are powers of ten, so we have the very familiar 1000s, 100s, 10s and 1s. Each column is ten times the one to the right.

In binary, each column headings are powers of two so each column is double the one to the right. We only need to remember the first eight (for this course), so this gives us:

128 64 32 16 8 4 2 1

Converting Between Binary and Denary

You may be asked to convert between binary and denary numbers. These two slideshows show you a good way of doing it. Watch them both, click through the slides.

Binary to Denary Conversion
Denary to Binary conversion

How to do Binary Addition

Addition in binary is exactly the same as in denary.

You should arrange the two binary numbers above each other so that the columns line up. Start on the rightmost digit and add them. If there are any carries, write them down next to the next left column.

The animation on the right shows this in more detail.

The exam will often have a sum whose answer doesn't fit into eight columns. As the memory in a computer is arranged in eight bit bytes, this can cause a problem.

This situation is known as an "overflow error", and if your program hasn't been written to expect a nine bit answer, it may not function properly. The answer will either be wrong as the ninth bit will be ignored, or the program will produce a result which doesn't fit into the storage space allocated to it (one eight bit byte)

In practice, an overflow error is unlikely to cause an issue as most programming languages will handle a large number easily by using an appropriate data type.

Binary addition

Hexadecimal

We have looked at our normal decimal, or denary number system, as well as binary. These two systems are also know as base 2 and base 10. In denary (base 10), each column is 10 tines larger than the one one the right and in binary each column is two times larger. We can in fact use any number for this, so we could have base 3 (called ternary), base 4 (quaterny) etc.

Computer scientists often use two other number systems, they are octal (base 8) and hexadecimal (base 16). For your GCSE Computer Science exam, you need to know why we would use hexadecimal rather than any other base.

Why Use Hexadecimal?

We have seen that computers only stored data using two states, on or off. We often need to use the binary representation of large groups of binary digits. This can be very difficult for humans because:

  • The binary digits all look the same!

  • It is difficult to remember large amounts of 1s and 0s because we cant remember where we have got to.

  • It is difficult to write down and copy large binary numbers - mistakes are often made.

It is quite easy to convert binary and denary numbers into another number system, base 16 or hexadecimal.

Untitled presentation

Converting Between Denary and Hexadecimal

Convert from Hexadecimal to Denary Method 1

  1. Split the Hexadecimal number into two separate numbers
    i.e. A9 would be split into A and 9

  2. Convert each hexadecimal digit into binary
    i.e. A is 1010 and 9 is 1001

  3. Combine the two binary numbers into one eight bit binary number
    i.e. A9 becomes 10101001

  4. Convert the binary number into denary
    i.e. 10101001 > 128 + 32 + 8 + 1 = 169
    ∴ Hexadecimal A9 = denary 169


Converting Hexadecimal Numbers to Binary Method 1

Convert from Hexadecimal to Denary Method 2

We have already seen that when we have a two digit hexadecimal number the two digits are in the first two columns. Because hexadecimal is base 16, the first digit is how many "16s" are in that number.

All we need to do to convert a two digit hexadecimal number to denary is apply this formula:

First digit x 16 + second digit

Of course, either digit may be a number or a letter. If it is a letter simply convert the letter back to denary.

Example: Convert the hexadecimal number 8B to denary

denary = (8 * 16) + B which is the same as

denary = 8 * 16 + 11

= 139

Converting from Denary to Hexadecimal

There are two ways of converting from denary to hexadecimal. Essentially, they are the reverse of the two methods you have just seen for converting from hexadecimal to denary:

Converting Between Binary and Hexadecimal

The easiest way to convert from binary to hexadecimal is to split the binary number into four bit nibbles, and then convert each nibble to hexadecimal (you can convert the nibble to denary first, if you find that easier). If you find that one of the original binary number doesn't give four bit nibbles, then you must make sure that the nibble on the left is the one with less than four bits.

Example 1

Convert 11000011 to hexadecimal

11000011 becomes 1100 and 0011

1100 is 12 in denary, which is C in hexadecimal. 0011 is 3 in denary.

11000011 in binary is C3 in denary

Example 2

Convert 1011011 to hexadecimal

1011011 becomes 101 and 1011 (the first nibble must be the one with less than four bits)

101 is 5 in denary. 1011 is 11 in denary which is B in hexadecimal.

1011011 is 5B in hexadecimal.

Binary Shifts

Binary numbers can be manipulated in several ways. One of these is called a binary shift.

All this means is that the whole binary number is moved to the left or the right by a number of places.

In your exam, you may be asked to perform a binary shift on a number, and explain what effect that it has had on the number's value.

This diagram should explain!

Left binary shifts always make the number longer, and therefore bigger. Each place it shifts will double the value. A binary left shift of one place (sometimes written <<1) will double the value, a binary left shift of two places (<<2) with double, then double again - so multiply by four)

Right binary shifts make the number shorter, and smaller. The right most digit is "lost", so we forget about it. A binary right shift of one place (written as >>1) halves the number, and a binary right shift of two places (>>2) will halve and halve again, so it will divide by four.

It may help you to remember that you "pick" the whole number up and move it left or right.


Quick Test (will be here) (Requires login)

Other Resources for this topic

This section has four pages (click on links)

Binary representation of Numbers (this page)

πŸ”— Binary representation of Characters

πŸ”— Binary representation of Images

πŸ”— Binary representation of Sound

Next section:

πŸ”—1.2.5 Compression