Understanding Numeric Data in VBScript - Number systems
(Page 3 of 5 )
Keeping in mind that computers interpret bit patterns, humans on the other hand must use more friendly numbers. Different number systems have been devised to ease interpreting different types of numbers.
By far the most common among these number systems is the decimal system that we use every day. This base-10 system was designed to make mathematical calculations much easier—for the human mind that is. The decimal system is harder for computers.
Computer hardware uses the base-2 binary system. This is because CPUs use transistors to perform logical calculations. A transistor has two states: open and closed. This made the binary system a natural choice.
A number system’s base implies the number of possibilities for each digit in a number. Since the binary system allows only two possibilities, it is much faster for a CPU to use these types of numbers. Let’s take a look at the digit possibilities for common number systems:
- Binary system – 0, 1
- Octal system – 0, 1, 2, 3, 4, 5, 6, 7
- Decimal system – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
- Hexadecimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
In hexadecimal (base-16) there are sixteen possibilities for each digit. Since they can’t be expressed in single decimal digits, letters are used to represent the values 11 to 15.
Counting in Different Number Systems |
Bin | Dec | Hex | Bin | Dec | Hex | Bin | Dec | Hex |
0 | 0 | 0 | 1001 | 8 | 8 | 10001 | 16 | 10 |
1 | 1 | 1 | 1010 | 9 | 9 | 10010 | 17 | 11 |
10 | 2 | 2 | 1011 | 10 | A | 10011 | 18 | 12 |
11 | 3 | 3 | 1100 | 11 | B | 10100 | 19 | 13 |
100 | 4 | 4 | 1101 | 12 | C | 10101 | 20 | 14 |
101 | 5 | 5 | 1110 | 13 | D | 10110 | 21 | 15 |
110 | 6 | 6 | 1111 | 14 | E | 10111 | 22 | 16 |
1000 | 7 | 7 | 10000 | 15 | F | 11000 | 23 | 17 |
All number systems increment by one starting at zero. Adding numbers in each system is done identically—increment the furthest right digit by one; if it is already at its maximum, reset it to zero and carry to the next place.
An example in hex would be 4A6FF + 1 = 4A700.
Since numbers inherently represent the same quantities, and the mathematical operations on them are the identical, numbers can be converted from one system to another. Since we’re dealing with computers, let’s take a look at how to convert a bit string (from binary) to both octal and hex.
- One Octal digit equals three binary digits:
101 | 101 | 011 | 100 | 101 | 000 | 001 | 011 |
5 | 5 | 3 | 4 | 5 | 0 | 1 | 3 |
- One Hexadecimal digit equals four binary digits:
1011 | 0101 | 1100 | 1010 | 0000 | 1011 |
B | 5 | C | A | 0 | B |
Now that you have a better understanding of number systems, let’s take a look at how VBScript makes it easier for you to work with them.
Next: Conversion Functions >>
More BrainDump Articles
More By Nilpo