Architecture 3 - Adding For Big Boys And Girls

 

One of the outcomes for Computer Architecture is learning how to add and subtract numbers in different bases.  This may seem like a meaningless exercise, but actually grasping the concept of it is quite important!

The successful execution of any software depends on the changing of 0-1 patterns, held in the processor.  Any item of software or data can be reduced, at its most fundamental level, to a string of 0s and 1s.  Even a full-length 3D movie is nothing more, to a computer, than billions of  0s and 1s.  It is when that pattern of digits changes, that the movie, or software, or whatever, will run, or the data will change.

Binary numbers in a processor As a simple example, the letter “A” is held in memory as 100 0001.  If I wanted to delete the uppercase “A” and replace it with a lowercase “a”, the bit pattern in the memory would change to 110 0001, and the lowercase “a” would be displayed instead.  (We will look at letters and text in more detail when we come to look at the ASCII table in a later tutorial).

In order to understand, therefore, how programs run, we have to understand how bit patterns can be changed, and one of the easiest ways to do this is to learn how to add and subtract numbers together.

Adding in Denary (Easy)

When you learned to add and subtract in Primary School, you probably learned about “hundreds, tens and units”.  This is a simpler way of saying “place value” – in other words, the position of a number in relation to the other numbers, determines what it is worth.  For example –

103 – the “3” here is worth 3
537 – the “3” here stands for 30, as it means “3 lots of 10” (it’s in the 10s column)
392 – the “3” here means 300, because it’s in the “hundreds” column
Counting in Binary

…and so on.  Every time we add a column to the left, we are increasing the value by a power of 10.  So we would then have 3 000, 30 000, 300 000 and so on.

If we add two numbers together, we are only allowed to go up to 9 before we have to move to the next column.

Decimal addition

This is so straightforward that you have probably been doing this for years, without even thinking about it!  But now you will have to carefully consider how this works, as we will be moving out of the “comfort zone” of Base 10 numbers and onto Binary ones.  We will start with an 8-bit number, although typical exam questions can be anything up to 16 bits.

Adding in Binary (Harder)

Binary Addition

If you have done this right, you should never have to worry about adding more than 3 binary ones together. ( If you ever find yourself having to deal with 1+1+1+1, you’ve done something wrong, so go back and check!)

What would happen if the 128’s column added up to 2 or 3?  Click here to get the answer.

Adding in Hexadecimal (Requires Concentration)

You will also be required to add two hexadecimal numbers together.  This follows the same format as the denary and binary additions, except that this time, your columns will come in lots of 16.  Most students find that Hex arithmetic is hardest of all, because it’s easy to forget that you are dealing with 16s and slip back into using 10’s.

Hexadecimal addition

Remember to put your lowercase h at the end, to show people that it’s a hexadecimal base number!

Brain Training

Up until 1971, the coinage system in Britain followed no fewer than three different bases (ask your Gran!)  This was because it was based on the Roman system of  librii, soldii, dinarii which was commonly abbreviated to LSD. (Our £ symbol today is based on the Roman “L”, for Librii. )

In the pre-decimal money system, 12 old pennies made a shilling.  You wrote it like this – 12d = 1/-

And 20 shillings made a pound – 20/- = £1.

21 shillings made a Guinea, and just to add to the fun you also had 1/2d (halfpennies) and 1/4d (farthings) to contend with as well!

Victorian schoolchildren were faced with hard sums like this on a daily basis, and no calculators –

LSD addition example

To do this addition, you have to think in base 12 for the pennies, base 20 for the shillings and base 10 for the pounds!  Here we go –

LSD addition

So the final answer would be £13-10-9 1/4.  (Thirteen pounds, ten shillings, nine and a farthing).

You can see why whole generations of schoolchildren and shopkeepers breathed a collective sigh of relief on 15 February 1971 – “Decimal Day”.

Try These Yourselves!

Highlight with your mouse to see the answers.

1011 0110 + 0101 1111 = 1 0001 0101

F437 + 7C10 =  17047h

£3-17-6 + £9-13-11 ½ = £13-11-5 1/2

1101 0010 0011 + 1010 0101 1100 = 1 0111 0111 1111

C54 + 69A = 12EEh

£4-2-11 ½  + £17-13-5 ½ = £21-16-5

1011 0111 0011 1011 + 0101 0001 0110 1111 = 1 0000 1000 1010 0101

67BA + C79C = 12F56h

£13-12-9 ¾ + £15-18-2 ½ = £29-11-0 ¼

Now that you are confident with adding numbers in different bases, why not try some subtraction instead?

 

 

Links

  • Home
  • Computing Stuff
  • Architecture 1 - Basic Concepts
  • Architecture 2 - Vexed by Hex?
  • Architecture 4 - Subtracting For The Terrified

Website design copyright © 2009 Metamorphoozis. Content copyright © 2009/10 C Nyssen
XHTML | CSS