Number Systems — Study Notes
What to learn in Number Systems
A computer stores everything — numbers, letters, pictures, sound — as patterns of two voltages, off and on. The papers call those two states 0 and 1, and the whole of this topic is how quantities are written in 0s and 1s, how the short forms octal and hexadecimal stand in for long strings of bits, how negative numbers are stored, and how letters are coded as numbers. Learn it in this order: first the four systems and what each one is for, then the two conversion methods, then the grouping shortcut between binary, octal and hexadecimal, then binary fractions, then binary arithmetic, then the complements that store negative numbers, then the codes — BCD, Excess-3, Gray, ASCII, EBCDIC and Unicode — and finally the bits, bytes and units. Every section ends in worked examples, because the papers never ask for a definition on its own: they give a number in one system and ask for it in another, or they give a code and ask what it stands for. Work each example with a pencil before you look at the answer, and the conversions become automatic. The questions on this page are 103 in number: 90 from past papers and the bank, and 13 new ones written for the facts the bank did not cover — the octal and hexadecimal conversions, the complements worked out, BCD, ASCII and Gray code, and binary fractions.
The four number systems: base, digits and uses
A number system is positional: each digit is worth its own value multiplied by a power of the base, and the power depends on the digit's place. The base, also called the radix, is simply how many different digits the system uses, and every digit must be smaller than the base. The digit just left of the point always has weight 1, the next has weight equal to the base, the next the base squared, and so on; after the point the weights are one over the base, one over the base squared, and so on. So 1011 in binary means 1 x 8 + 0 x 4 + 1 x 2 + 1 x 1, which is 11 in decimal, and 347 in octal means 3 x 64 + 4 x 8 + 7 x 1, which is 231. Binary is the computer's own language, because a circuit only has two states. Octal and hexadecimal are shorthand for humans: they pack long bit strings into a few readable characters, which is why memory addresses and colour codes are written in hexadecimal. Decimal is the system people count in, and it is the system every conversion is checked against.
Binary — base 2, digits 0 and 1
- Used inside the computer: every bit is one 0 or one 1, off or on.
- One byte is 8 bits, so 8 bits represent 256 different values, 0 to 255.
- A computer primarily uses the binary system; its machine language consists of ones and zeros.
Octal — base 8, digits 0 to 7
- One octal digit stands for exactly three bits, because 2 to the power 3 is 8.
- Used as a compact shorthand for binary; an octal digit is never 8 or 9.
- Example: (17) in octal is 1 x 8 + 7, which is 15 in decimal.
Decimal — base 10, digits 0 to 9
- The system people count in; every conversion is checked against it.
- Example: 472 in decimal is 4 x 100 + 7 x 10 + 2 x 1.
Hexadecimal — base 16, digits 0 to 9 and A to F
- A stands for 10, B for 11, C for 12, D for 13, E for 14 and F for 15.
- One hexadecimal digit stands for exactly four bits; one byte is exactly two hexadecimal digits, so FF is 255.
- Used for memory addresses, machine code and colour codes — wherever long bit patterns must be readable.
The first sixteen numbers, in all four systems
- 0 is 0 in binary, 0 in octal, 0 in hexadecimal; 7 is 111 in binary, 7 in octal, 7 in hexadecimal.
- 8 is 1000 in binary, 10 in octal, 8 in hexadecimal; 9 is 1001 in binary, 11 in octal, 9 in hexadecimal.
- 10 is 1010 in binary, 12 in octal, A in hexadecimal; 15 is 1111 in binary, 17 in octal, F in hexadecimal.
How to convert: the two methods that do all the work
Every conversion uses one of two methods, and nothing else. To go from any base to decimal, expand the number by its positional weights and add: each digit multiplied by its place value. So (101101) in binary is 32 + 0 + 8 + 4 + 0 + 1, which is 45; (2F) in hexadecimal is 2 x 16 + 15, which is 47; and (25) in octal is 2 x 8 + 5, which is 21. To go from decimal to any base, divide the integer part by the target base again and again, write down each remainder, and read the remainders from the last one back to the first — the remainders come out from right to left, so reading them upward is the whole trick. So 25 in decimal divided by 2 gives remainders 1, 0, 0, 1, 1, read upward as 11001 in binary; 83 divided by 8 gives 10 remainder 3, 10 divided by 8 gives 1 remainder 2, 1 divided by 8 gives 0 remainder 1, read upward as 123 in octal; and 171 divided by 16 gives 10 remainder 11, which is B, and 10 divided by 16 gives 0 remainder 10, which is A, read upward as AB in hexadecimal. A fraction is converted separately, by repeated multiplication: multiply the fraction by the target base, write down the whole-number part of each product as the next digit, and carry the fractional part on. So 0.625 in decimal multiplied by 2 gives 1.25, write 1; 0.25 multiplied by 2 gives 0.5, write 0; 0.5 multiplied by 2 gives 1.0, write 1 — so 0.625 is 0.101 in binary.
Any base to decimal — positional expansion
- Multiply each digit by its place value (powers of the base) and add.
- Binary 1011 is 8 + 0 + 2 + 1, which is 11; octal 17 is 8 + 7, which is 15; hexadecimal 2A is 32 + 10, which is 42.
Decimal to any base — repeated division
- Divide by the target base, keep the remainder, divide the quotient again until it reaches 0.
- Read the remainders from the last one back to the first: 25 in decimal is 11001 in binary, 83 is 123 in octal, 171 is AB in hexadecimal.
Fractions — repeated multiplication
- Multiply the fraction by the target base; each whole-number part is the next digit.
- 0.625 in decimal is 0.101 in binary; a decimal fraction that does not terminate in binary, such as 0.1, repeats for ever — which is why a computer cannot store 0.1 exactly.
Binary, octal and hexadecimal: the grouping shortcut
Because 8 is 2 to the power 3 and 16 is 2 to the power 4, binary converts to octal and hexadecimal by grouping bits, with no decimal step in between — and this is the fastest method in the paper. For octal, split the bits into groups of three, starting from the binary point and working outward, padding with zeros at the outer ends only when a group is short. So 110101 in binary groups as 110 and 101, which are 6 and 5, so it is 65 in octal; and 101101 groups as 101 and 101 for octal, but for hexadecimal it groups in fours. For hexadecimal, split into groups of four from the point: 101101 becomes 0010 and 1101, which are 2 and D, so it is 2D in hexadecimal; and 1110 on its own is a single group of four, so it is E. Going the other way, expand each digit: each octal digit becomes its three-bit group and each hexadecimal digit its four-bit group, so octal 65 becomes 110 101 in binary and hexadecimal 2D becomes 0010 1101. To go from octal to hexadecimal, or back, go through binary: expand into bits, then regroup. The commonest slip is grouping from the wrong end — always start at the binary point, never at the left-hand end of a long number.
Worked grouping conversions
- Binary 110101 to octal: 110 101 gives 6 and 5, so 65 in octal.
- Binary 101101 to hexadecimal: 0010 1101 gives 2 and D, so 2D in hexadecimal.
- Binary 1110 to hexadecimal: one group of four, so E.
- Hexadecimal FF to binary: F is 1111, so FF is 1111 1111, which needs 8 bits.
Binary fractions
The point works the same way in every base: the first place after it is worth one over the base, the second one over the base squared, and so on. In binary the places after the point are worth 1/2, 1/4, 1/8, 1/16, and each next place is half the one before. So 0.101 in binary is 1/2 + 0/4 + 1/8, which is 0.5 + 0.125, which is 0.625 in decimal; and 101.101 in binary is 4 + 0 + 1 + 1/2 + 0/4 + 1/8, which is 5.625. To convert a decimal fraction to binary, multiply by 2 repeatedly and read the whole-number parts downward, as shown above for 0.625. Not every decimal fraction terminates in binary: 0.1 in decimal repeats for ever in binary, so a computer stores only an approximation of it — the reason 0.1 + 0.2 does not come out exactly 0.3 in a program. In the papers, fractions are asked as single worked values, so learn the weights 1/2, 1/4 and 1/8 by heart and the rest follows.
Fraction weights to learn
- After the binary point: 1/2, then 1/4, then 1/8, then 1/16.
- 0.101 in binary is 0.625 in decimal; 101.101 in binary is 5.625 in decimal.
- Decimal 0.625 to binary is 0.101, by repeated multiplication by 2.
Binary arithmetic: add, subtract and multiply
Binary addition has only four rules: 0 + 0 is 0, 0 + 1 is 1, 1 + 0 is 1, and 1 + 1 is 10 — that is, 0 with a carry of 1 into the next place. So 101 (which is 5) plus 11 (which is 3) is 1000 (which is 8): the rightmost column 1 + 1 gives 0 carry 1, the next column 0 + 1 plus the carry gives 0 carry 1, and the next column 1 plus the carry gives 0 carry 1, leaving 1000. Adding 1 to 1111 (which is 15) ripples the carry through all four 1s and gives 10000 (which is 16). Two high bits added together give 10, never 11 — the papers ask exactly that. Subtraction is done by borrowing, exactly as in decimal, or by the 2's complement method in the next section, which is how the hardware does it. Multiplication works like decimal long multiplication: multiply by each bit (which is either multiply by 0 or by 1) and add the shifted partial products. The trap is the carry: a column can only hold 0 or 1, so every time two 1s meet, a 1 carries left.
Addition rules
- 0 + 0 is 0; 0 + 1 is 1; 1 + 0 is 1; 1 + 1 is 10, carry 1.
- 101 + 11 is 1000, because 5 + 3 is 8; 1111 + 1 is 10000, because 15 + 1 is 16.
- Two high bits added give 10.
Negative numbers: sign-magnitude, 1's complement and 2's complement
A fixed number of bits can only hold so many values, so the papers ask how negative numbers are fitted in. There are three schemes. In sign-magnitude, the leftmost bit is the sign — 0 for positive, 1 for negative — and the rest hold the size, so in 4 bits +5 is 0101 and -5 is 1101. In 1's complement, a negative number is made by flipping every bit: the 1's complement of 1101 is 0010, and of 1010 it is 0101. In 2's complement, take the 1's complement and add 1: the 2's complement of 0110 is 1001 + 1, which is 1010, so 1010 in 4-bit 2's complement means -6; and the 2's complement of 0101 is 1010 + 1, which is 1011, so 1011 means -5. Both sign-magnitude and 1's complement have two zeros, +0 and -0; 2's complement has a single zero and one extra negative value, which is why it is the most widely used method for signed integers in modern computers: the same adder does addition and subtraction, and there is no second zero to handle. The range of an n-bit 2's complement number is from -2 to the power (n-1) up to +2 to the power (n-1) minus 1, so 8 bits cover -128 to +127, while sign-magnitude and 1's complement cover only -127 to +127. Subtraction uses the complement: A minus B is A plus the 2's complement of B, dropping any carry out of the sign bit. So 7 minus 3 is 0111 plus 1101 (the 2's complement of 0011), which is 1 0100; drop the carry and the answer is 0100, which is 4.
The three schemes, for 4 bits, value -5
- Sign-magnitude: 1101; range -7 to +7; two zeros.
- 1's complement: 1010; range -7 to +7; two zeros; add with end-around carry.
- 2's complement: 1011; range -8 to +7; one zero; the standard in hardware.
Ranges to learn
- 4 bits: 2's complement -8 to +7; sign-magnitude and 1's complement -7 to +7.
- 8 bits: 2's complement -128 to +127; the other two -127 to +127.
- 16 bits: 2's complement -32,768 to +32,767.
Subtraction by 2's complement
- A minus B is A plus the 2's complement of B; drop the carry out of the sign bit.
- 7 minus 3: 0111 + 1101 is 1 0100, drop the carry, answer 0100, which is 4.
Codes that are not numbers: BCD, Excess-3, Gray, ASCII, EBCDIC and Unicode
Not everything stored as bits is a number. BCD, short for Binary Coded Decimal, codes each decimal digit separately in four bits: 59 in BCD is 0101 1001 — 5 is 0101 and 9 is 1001 — while 59 in plain binary is 111011, a completely different pattern, so BCD is not the same as binary and the papers test exactly that confusion. Six of the sixteen 4-bit patterns, 1010 to 1111, are invalid in BCD, because no decimal digit needs them. Excess-3 is BCD with 3 added to each digit, so 5 becomes 1000; it is self-complementing, meaning that flipping the bits of a digit's code gives the code for 9 minus that digit. Gray code is different again: successive values differ in exactly one bit, so 0, 1, 2, 3 in Gray are 000, 001, 011, 010. To convert binary to Gray, keep the leftmost bit and XOR each bit with the one to its left: binary 1011 gives Gray 1110. Gray code is used in rotary encoders and in Karnaugh maps, wherever a half-changed code would be misread. ASCII, the American Standard Code for Information Interchange, is a 7-bit code with 128 characters: the capital letter A is 65, the small letter a is 97 and the digit character 0 is 48, so upper and lower case differ by 32. EBCDIC is an 8-bit code from IBM, used on its mainframes. Unicode covers the world's scripts; its dominant encoding, UTF-8, keeps ASCII as its first 128 code points, so every ASCII text is also valid UTF-8. The full forms of ASCII and BCD are asked on the Computer Abbreviations page, and the number facts — primes, divisibility, HCF and LCM — belong to the Mathematics Number System page, not this one.
BCD (8421)
- Each decimal digit in 4 bits: 59 is 0101 1001; 473 is 0100 0111 0011.
- Patterns 1010 to 1111 are invalid in BCD.
- BCD is not binary: 59 in binary is 111011.
Excess-3 and Gray code
- Excess-3 is BCD plus 3 for each digit; it is self-complementing.
- Gray code: neighbours differ in exactly one bit; binary 1011 gives Gray 1110.
- Gray code is used in shaft encoders and Karnaugh maps.
ASCII, EBCDIC and Unicode
- ASCII is 7-bit, 128 characters: A is 65, a is 97, 0 is 48; cases differ by 32.
- EBCDIC is an 8-bit IBM code.
- Unicode covers all scripts; UTF-8 keeps ASCII as its first 128 code points.
Bits, bytes, nibbles and the units
The vocabulary underneath all of this is small and the papers ask it constantly. A bit is one 0 or one 1, the smallest unit of data. Four bits make a nibble, and eight bits make a byte — one byte is two nibbles, and one byte normally stores one character. Eight bits represent 256 different values, 0 to 255, which is why the largest unsigned byte value is 255 and why hexadecimal FF, which is two groups of four bits, needs exactly 8 bits. The storage units step by 1024 in the papers' usage: one kilobyte is 1024 bytes, so one kilobyte is 8192 bits and 2048 nibbles; one megabyte is 1024 kilobytes and one gigabyte is 1024 megabytes. The SI prefixes go by powers of ten — 10 to the power 12 is Tera, so a terabyte drive holds a trillion bytes in decimal counting — and in decimal units one petabyte is 1,000,000 gigabytes. Keep the two countings apart: the papers use 1024 for kilobyte, megabyte and gigabyte, and powers of ten for the named prefixes Kilo, Mega, Giga and Tera when they ask what 10 to the power 12 is.
The units
- 1 bit is one 0 or 1; 1 nibble is 4 bits; 1 byte is 8 bits, which is 2 nibbles.
- 8 bits represent 256 values, 0 to 255.
- 1 kilobyte is 1024 bytes, 8192 bits and 2048 nibbles.
- 1 megabyte is 1024 kilobytes; 1 gigabyte is 1024 megabytes.
- 10 to the power 12 is Tera; 1 petabyte is 1,000,000 gigabytes in decimal units.
What the papers ask, and the traps
The papers ask this topic as short conversions and short facts, and the traps are always the same few. Hexadecimal F is 15, not 16 — 16 is the base, not the value of F. In binary, 1 + 1 is 10, not 2 and not 11. BCD 59 is 0101 1001, not 111011, which is 59 in plain binary. An octal number never contains 8 or 9, and a binary number never contains 2. The 8-bit 2's complement range is -128 to +127, not -127 to +127 — the extra negative value is the whole point of 2's complement. One kilobyte is 1024 bytes in the papers, not 1000. A binary fraction is read by halves: 0.101 is 0.625, not 0.101 in decimal. And the ASCII codes to carry in your head are A is 65, a is 97 and 0 is 48. Two boundaries to keep straight: number theory — prime and composite numbers, divisibility rules, HCF and LCM — is asked on the Mathematics Number System page, so if a question is about whether a number is prime or divisible, it belongs there; and the full forms of ASCII, BCD and the other abbreviations are asked on the Computer Abbreviations page. This page owns the computer side only: the four systems, the conversions, the complements, the codes and the units.
More facts to learn
- <p><b>In the binary number system, how many different digits are used?</b><br>Two digits, 0 and 1.</p> <p><b>Which number system uses only the digits 0 and 1?</b><br>Binary</p> <p><b>What is the base of the binary number system?</b><br>2.</p> <p><b>Which number system uses only the digits 0 to 7?</b><br>Octal.</p> <p><b>How many different digits are used in the octal number system?</b><br>8 digits</p> <p><b>How many different digits are used in the hexadecimal number system?</b><br>16</p> <p><b>Which number system uses the digits 0 to 9?</b><br>Decimal number system</p> <p><b>The octal number system uses base:</b><br>8</p> <p><b>The hexadecimal number system uses base:</b><br>16</p> <p><b>A computer primarily uses which number system?</b><br>Binary</p> <p><b>The number system used by digital computers to process quantitative information is?</b><br>Binary</p> <p><b>Which are binary numbers?</b><br>0 and 1</p> <p><b>The binary number system uses:</b><br>0 and 1</p> <p><b>Which digits does the binary number system use?</b><br>0 and 1</p> <p><b>What is the binary number system based on?</b><br>0 and 1</p> <p><b>Which two digits are used in the binary number system?</b><br>0 and 1.</p> <p><b>How many options does a binary choice offer?</b><br>two</p> <p><b>Which of those sets is not binary</b><br>50.40,30,20,10</p> <p><b>Each type of computer has its own machine language which consists of _____:</b><br>Both A & B</p> <p><b>What is the decimal equivalent of the binary number 101?</b><br>5</p> <p><b>What is the decimal equivalent of the binary number 110?</b><br>6</p> <p><b>How is the decimal number 7 written in binary?</b><br>111</p> <p><b>What is the decimal equivalent of the binary number 1001?</b><br>9</p> <p><b>What is the decimal equivalent of the binary number 1110?</b><br>14</p> <p><b>What is the decimal equivalent of the binary number 1011?</b><br>11</p> <p><b>What is the decimal equivalent of the binary number 1100?</b><br>12.</p> <p><b>What is the decimal equivalent of the binary number 1111?</b><br>15</p> <p><b>What is the decimal equivalent of the binary number 1000?</b><br>8.</p> <p><b>What is the decimal equivalent of the binary number 100?</b><br>4.</p> <p><b>How is the decimal number 10 written in binary?</b><br>1010</p> <p><b>What is the decimal equivalent of the binary number 1101?</b><br>13.</p> <p><b>How is the decimal number 13 written in binary?</b><br>1101</p> <p><b>What is the decimal equivalent of the binary number 10000?</b><br>16.</p> <p><b>What is the decimal equivalent of the binary number 10100?</b><br>20</p> <p><b>What is the binary number 111 in decimal?</b><br>7</p> <p><b>How is the decimal number 20 written in binary?</b><br>10100</p> <p><b>The binary number 10010 is equal to which decimal number?</b><br>18</p> <p><b>In the binary number system used by computers, the digits 1000 stand for which ordinary decimal number?</b><br>8.</p> <p><b>What is the decimal equivalent of the binary number 10101?</b><br>21.</p> <p><b>What is the decimal equivalent of the binary number 11101?</b><br>29</p> <p><b>What is the binary equivalent of the decimal number 10?</b><br>1010</p> <p><b>What is the binary equivalent of the decimal number 3?</b><br>11</p> <p><b>In binary representation, what is the decimal equivalent of 1011?</b><br>11</p> <p><b>What is the binary value of the decimal number 13?</b><br>(1101)2</p> <p><b>What is the decimal value of the binary number (1011)2?</b><br>11</p> <p><b>What is the decimal value of the binary number 11010?</b><br>26</p> <p><b>What is the binary equivalent of the decimal number 45?</b><br>101101</p> <p><b>Convert the decimal number 10 to binary.</b><br>1010</p> <p><b>The decimal equivalent of binary 1010 is:</b><br>10</p> <p><b>The binary equivalent of decimal 15 is:</b><br>1111</p> <p><b>The decimal equivalent of binary 1010 is10
- The decimal equivalent of binary 1100 is what?</b><br>12</p> <p><b>The binary equivalent of decimal 5 is101
- The binary equivalent of decimal 7 is what?</b><br>111</p> <p><b>The binary equivalent of decimal 10 is1010
- The binary equivalent of decimal 8 is what?</b><br>1000</p> <p><b>Convert decimal 10 into binary.</b><br>1010</p> <p><b>The binary equivalent of the decimal number 13 is?</b><br>1101</p> <p><b>What is the binary equivalent of the decimal number 5?</b><br>101</p> <p><b>What is the decimal value of the binary fraction 0.101?</b><br>0.625</p> <p><b>What is the decimal equivalent of the octal number 17?</b><br>15.</p> <p><b>What is the binary number 110101 in octal?</b><br>65</p> <p><b>What is the decimal value of the octal number 34?</b><br>28</p>