Binary Arithmetic
Written by Mike James   
Article Index
Binary Arithmetic
Choosing the right base
Decimal not dead yet

What could be simpler than binary arithmetic? It’s just two-fingered counting and, once you know how it works, it seems natural for a computer to use it. But decimal is so built into our hands that it took quite a long time before we realized that two fingers were enough.

The duo-decimal system

We are so used to counting and doing simple arithmetic that we tend to forget that if you don’t choose the right system then it all looks very difficult.

You might think that using a decimal place value system is so blindingly obvious that only an idiot would use anything else - but it isn’t that long since the UK dropped the mixed base duo-decimal monetery system, The duo-decimal system is a good example of a mixed based system. This counted first in base 12 to get shillings and then in base 20 to get pounds.

The imperial system of weights and measures still hangs on in both the USA and the UK and it’s even more eccentric. For example, weight is counted first to base 16 (ounces to pounds), then base 14 (pounds to stones) then base 8 (stones to cwt) and then base 20 (cwt to tons)!

So much for the attractive simplicity of the base ten place value system!

However this doesn’t mean that any old system of numbers works as well as any other. It has even been suggested that the Romans would have been better engineers if it wasn’t for their incredibly complicated mixed-base no-place value system.

Exactly how you count affects how easy it is to perform arithmetic and hence counting matters.

Base and place

So what is a “place value” system and how does it work?

The idea is that you first choose your base and arrange to have just enough symbols, any symbols you like, to count up to one less than this value.

For example, if you choose 3 as the base you need symbols for 0, 1, and 2 but you could just as easily use the symbols A, B and C. The symbols don't matter but in most cases we pick the traditional digits for values up to nine even though this risks confusion with a decimal system. 

Counting in base three leads quickly to a problem common to all counting systems that use a limited number of symbols.

What do you do when you get to 2 and need to count to 3? Remember you only have the symbols 0, 1 and 2.

The answer should be familiar to any digit-counting human - you make a group of three, i.e. 1 group of three and nothing extra,  which you write down as 10. Notice that this is not “ten” but “one zero in base 3”.

 

base310

 

Then you carry on counting: 11 (i.e. 1 lot of 3 and 1), 12 (i.e. 1 lot of 3 and 2) and then you reach another group of 3.

So now you have two groups of 3 which you write down as 20 which is not “twenty” but “two zero in base 3”.

 

base320

 

You carry on like this until you reach 22 and adding one more makes this into three groups of three which you write 100, which means that you have one group of three groups of three.

base3100

 

Think of it as a hierarchy in which you build a group of three things each of which is in turn a group of three things and so on.

We could go on labouring this idea all day - but now you either see what is going on or you are totally confused. If you are confused then go through the same steps with the base you know best, i.e. base 10, and see what happens.

The place value system

The place value system is a remarkably clever invention because using it you can give a name to any number without the need for an infinite number of symbols.

You can see that you only need n symbols to count in base n, not n-1 because you also need zero to record no groups of n things. Conventionally we use the digits 0 to 9 for bases up to 10 and the letter of the alphabet for bases greater than ten.

The use of letters is something that makes a number system look very strange and it tends to frighten people but the principles are just the same.

For example, to count in hexadecimal, i.e. base 16, you need symbols for 0 to 15, i.e. one less than the base, and these are 0 to 9, A, B,C,D,E and F.

Counting in base 16 starts out exactly like counting base 10 i.e. 0,1,2,3,4,5,6,7,8 and 9, but you don’t go to ten next because you are counting in base 16 and you only move to the next place value when you have a group of 16 to notch up. Instead you use A for ten, B for eleven and so on until you reach F for 15.

Add one more and you have a group of 16 which you write down as 10 - again not “ten” but “one zero in base 16”. The rest is just more of the same but it still looks odd to refer to “FF” as a number - 255 to be exact - because that’s what 15 groups of 16 plus one group of 15 add up to.

<ASIN:0789736136>

<ASIN:0767917073>

<ASIN:3540689028>



 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.