Chapter 24.1 - Counting on your fingers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The next chapter digs inside the computer a bit, but before we look at that it would be as well to describe how computers count: they do it using the binary system, which means that they have no fingers - they are all thumbs. Most European languages count using a more or less regular pattern of tens - in English, for example, although it starts off a bit erratically, it soon settles down into regular groups: twenty, twenty one, twenty two,...,twenty nine thirty, thirty one, thirty two,...,thirty nine forty, forty one, forty two, ...,forty nine & so on, & this is made even more systematic with the Arabic numerals that we use. However, the only reason for using ten is that we happen to have ten fingers & thumbs. Now suppose Martians have three extra fingers on each hand (in so far as one can call them fingers): so instead of using our decimal system, with ten as its base, they use a hexadecimal (or hex, for short) system, based on sixteen. They need six extra hex digits in addition to the ten that we use, & they happen to write them as A, B, C, D, E & F. And what comes after F? Just as we, with ten fingers, write 10 for ten, so they, with sixteen, write 10 for sixteen. Their number system starts off:
If you are using hex notation & you want to make the fact quite plain, then write 'h' at the end of the number, & say 'hex'. For instance, for a hundred & fifty eight, write '9Eh' & say 'nine E hex'. You will be wondering what all this has to do with computers. In fact, computers behave as though they had only two digits, represented by a low voltage, or off (0), & a high voltage, or on (1). This is called the binary system, & the two binary digits are called bits: so a bit is either 0 or 1. In the various systems, counting starts off
The important point is that sixteen is equal to two raised to the fourth power, & this makes converting between hex & binary very easy. To convert hex to binary, change each hex digit into four bits, using the table above. To convert binary to hex, divide the binary number into groups of four bits, starting on the right, & then change each group into the corresponding hex digit. For this reason, although strictly speaking computers use a pure binary system, humans often write the numbers stored inside a computer using hex notation. The bits inside the computer are mostly grouped into sets of eight, or bytes. A single byte can represent any number from nought to two hundred & fifty five (11111111 binary or FF hex), or alternatively any character in the ZX81 character set. Its value can be written with two hex digits. Two bytes can be grouped together to make what is technically called a word. A word can be written using sixteen bits of hex digits, & represents a number from 0 to (in decimal) 216-1 = 65535. A byte is always eight bits, but words vary from computer to computer. Summary Decimal, hexadecimal & binary systems. Bits & bytes (don't confuse them) & words. |