[Tutor] Hex to Str - still an open issue

Alan Gauld alan.gauld at freenet.co.uk
Thu Feb 10 09:24:24 CET 2005

> I am not so clued up on the 'base 2' and 'base 8' stuff.
> Care to explain that a little?

base 2 is binary, base 8 is octal.
We normally use base 10 decimal.

The base refers to the biggest number that can be represented
by a single digit. (Actually one less than the base because we
start with zero!) Thus in base 10 we have digits 0,1,2...,8,9
In base 8 we have 0,1,2...,6,7 and in binary 0,1

When we need a number bigger than a single digit can represent
we add another column, so 9+1 = 10, that is 1 ten plus zero units.

Similarly in base 8 & + 1 = 10
ie one eight and no units

and in base 2, 1+1 = 10
ie one two and zero units.

So the same principles hold as we are used to in decimal but
they just kick in at different points. But these are just
representational issues, the underlying value is the same
in each of the following cases:

9  - base 10
11 - base 8
1001 -base 2

You might also find base 16 - hexadecimal, or more commonly just hex.
There the numbers between 10 and 15 are represented by letters:


So the decimal number 27 is represented in hex as


And to make it clear which base is being used computer
languages adopt a simple convention of prefixing the digit in
ambiguous cases:

012 = implies 12 in base 8 (because of the leading 0
0x12 = implies 12 in hex because of the leading 0x
12 = implies decimal 12, no prefix.

HTH, A web search on 'number bases' or 'binary numbers'
should throw up much more detailed info

Alan G.

More information about the Tutor mailing list