The decimal system
The numbering scheme in everyday use is the decimal (or denary) system and numbers are represented by 10 digits i.e. the numbers 0 to 9.
Counting starts at zero, (see counting wheels below). Rotating the wheel anticlockwise adds 1 to the current count until the number reaches 9 whereupon the count is reset to 0.
To count past nine, a second counting wheel is needed. Each time the first wheel goes from 9 to 0 the second wheel is incremented by 1 until the count reaches 99. At this point a third wheel must be added and so on. As the second wheel goes from 9 to 0 the third wheel is incremented by one.
Digits are weighted according to their column position (which is important) as shown in the table below. The table corresponds to the three counting wheels above. The number of segments on each wheel are the same and correspond to the number base orweighting. In the decimal number system the weighing is base 10.
For example the decimal number 764 can be written as
weight 102 101 100 hundreds tens units digit 7 6 4
I.e. 7 * 100 + 6 * 10 + 4 * 1 = 764.
This representation of a decimal number provides the formula for converting a number to a different base by a process of repeated division. The generalised formula is shown on the right. The % sign (or modulus) is the remainder when a number is divided by the base number
| 764 / 10 = 76 remainder 4 76 / 10 = 7 remainder 6 7 / 10 = 0 remainder 7 0 stop when zero. | number % base = remainder (or modulus) number = number / base |
The binary system

Well the binary numbering scheme uses only 2 digits for arithmetic, i.e. 1 and 0. The weighting is to the base 2.
- The values 1 and 0 can be represented in terms of boolean logic where True = 1 and False = 0.
- The binary number system is important in electrical terms, because true and false can also represent ON and OFF. This is all any digital computer can understand.
- One may be used to represent ON while 0 may represent OFF.
- The value ON usually being represented by a positive voltage level, while OFF is usually represented 0 volts.
Decimal to binary conversion
The formula developed above will now be used to convert the decimal number 764 to its binary equivalent by repeatedly dividing it by two.
764 / 2 = 382 remainder 0 LSB
382 / 2 = 191 remainder 0
191 / 2 = 95 remainder 1
95 / 2 = 47 remainder 1
47 / 2 = 23 remainder 1
23 / 2 = 11 remainder 1
11 / 2 = 5 remainder 1
5 / 2 = 2 remainder 1
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1 MSB
0 stop when zero.
below.
| weight | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
| decimal | 512 | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| binary | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
I.e. 764 = 1* 512 + 0* 256 + 1*128 + 1*64 + 1*32 + 1*16 +1*8 + 1*4 +0*2+0*1
The leftmost digit is the Most Significant Bit (MSB) the rightmost digit being the Least Significant Bit. (LSB).
Now 10 positions or bits, are needed to represent our decimal number 764.
The binary number system is the idea behind a computer data bus. This is how computers understand numbers, simply in terms of ON and OFF
Hexadecimal numbering
One other number scheme which is of interest is hexadecimal. This is counting to base 16. In the hexadecimal system the digits 0-9 are used along with the letters A - F. So in decimal, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
This is typically used to represent RGB color values. Two hexadecimal digits representing each of the color components. For example FF0000 is red ; i.e. the red component has a decimal value of 255
The hexadecimal equivalent of 764 decimal is
764 / 16 = 47 remainder 12 (i.e. C)
47 / 16 = 2 remainder 15 (i.e. F)
2 / 16 = 0 remainder 2
0 step when zero
weight 162 161 160 decimal 256 16 1 hexadecimal 2 F C
I.e. 764 = 2*256 + 15*16 + 12*1
function test()
{
//change number base up to base 36
var alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var output=0;
base = prompt("enter number base ");
number = prompt("enter number to convert");
number = number.toUpperCase();
pw = number.length -1;
for (i=0;i<number.length>0;i++)
{
digit = number.charAt(i);
num = alphabet.indexOf(digit);
output = Math.pow(base,pw-i)*num + output;
}
alert(number + " base " + base + " is\n" + output + " base 10");
}
| Attachment | Size |
|---|---|
| numberBase-Ex1.htm | 1.69 KB |
| numberBase-Ex2.htm | 1.65 KB |

