Base two, binary, writes every whole number with only the two digits 0 and 1. This lesson reads and writes binary numerals as sums of different powers of two, counts in binary, proves that k binary digits name exactly the numbers from 0 to 2ᵏ − 1, and shows why a 0 written at the end doubles a number. It also explains the words bit and byte and why computers work in base two.
Two digits
The smallest possible base is 2. A numeral system with base 2 is called the binary number system, from the Latin binarius, “two”.[1] Its only digits are 0 and 1: in binary notation each digit is either a 0 or a 1.[2] Everything in lesson 1.1 applies with b = 2: objects are bundled in pairs, pairs in pairs, and so on, and each digit says whether a group of its size is present (1) or not (0).
A bit is a symbol with two possible values, 0 and 1; the word is short for binary digit.[3] A row of bits, such as 1011, is a bit string, and the number of bits in it is its length.[4] The binary numeral of a number is a bit string.[5]
By lesson 1.1, place k of a binary numeral is worth 2ᵏ. The place values are the powers of two, which double from each place to the next: 2⁰ = 1, 2¹ = 2, 2² = 4, 2³ = 8, and so on; Powers lesson 1.1 computed them up to 2¹⁰ = 1,024.
Which number does 101101₂ name?
- The numeral has six places, worth 32, 16, 8, 4, 2, 1 from the left.
- The digits 1, 0, 1, 1, 0, 1 say which of them are present: 32, 8, 4 and 1.
- 101101₂ = 1 × 32 + 0 × 16 + 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 32 + 8 + 4 + 1.
Answer: 101101₂ = 45. Reading a binary numeral needs no multiplication at all: add the place values under the 1s.
Find 1₂, 10000000₂ and 11111111₂.
- 1₂ = 1 and 0₂ = 0: the two digits name the same numbers as in base ten.
- 10000000₂ has a single 1, in place 7: it names 2⁷ = 128.
- 11111111₂ = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. Its successor is 100000000₂ = 2⁸ = 256, by the successor rule of lesson 1.1, so 255 = 256 − 1.
Answer: 1, 128 and 255. A numeral with a single 1 names a power of two; a numeral of k ones names 2ᵏ − 1.
Someone reads 1010₂ as “one thousand ten”. What number is it really?
- The places of a four-digit binary numeral are worth 8, 4, 2 and 1, not 1,000, 100, 10 and 1.
- 1010₂ = 8 + 2 = 10.
Answer: ten. The numeral is read digit by digit, “one zero one zero, base two”, or by its value.
Sums of different powers of two
In a binary numeral every digit is 0 or 1, so the expansion of lesson 1.1 is a sum in which each power of two appears once or not at all. The theorem of lesson 1.1, with b = 2, therefore says something about powers of two.
Every whole number n ≥ 1 can be written as a sum of different powers of two, and in only one way.[6]
By lesson 1.1, n has exactly one binary numeral. Its expansion is the sum of the powers 2ᵏ in the places that hold a 1, each once. Conversely, a sum of different powers of two is the expansion of the binary numeral with a 1 in each of those places and 0 elsewhere. So sums of different powers of two and binary numerals correspond one to one, and since n has only one numeral, it has only one such sum.
To find the sum, and so the numeral, take the largest power of two that fits, then the largest that fits in what is left, and so on.
Let n ≥ 1, and let 2ᵏ be the largest power of two with 2ᵏ ≤ n. Then the binary numeral of n has its leftmost 1 in place k, and n − 2ᵏ < 2ᵏ.
Since 2ᵏ is the largest power not more than n, the next one is more: n < 2ᵏ⁺¹ = 2ᵏ × 2 = 2ᵏ + 2ᵏ. Taking 2ᵏ away from both sides, n − 2ᵏ < 2ᵏ. So what is left is less than 2ᵏ and is a sum of smaller powers of two; none of them is 2ᵏ again. Together with 2ᵏ they form the sum of the Theorem, whose largest power is 2ᵏ: the leftmost 1 is in place k.
Write 100 as a sum of different powers of two and as a binary numeral.
- The powers of two are 1, 2, 4, 8, 16, 32, 64, 128, …. The largest not more than 100 is 64 = 2⁶. 100 − 64 = 36.
- The largest power not more than 36 is 32 = 2⁵. 36 − 32 = 4.
- 4 = 2² is itself a power of two. Nothing is left.
- So 100 = 2⁶ + 2⁵ + 2²: 1s in places 6, 5 and 2, and 0s in places 4, 3, 1 and 0.
Answer: 100 = 64 + 32 + 4 = 1100100₂. Check: 64 + 32 = 96, and 96 + 4 = 100.
Someone writes 12 = 8 + 2 + 2 and then 12 = 1022₂. What went wrong?
- 8 + 2 + 2 = 12 is true, but it uses 2 twice. The digit 2 in “1022₂” records two groups of 2, and 2 is not a digit of base two.
- Two groups of 2 make one group of 4: 12 = 8 + 4.
- The largest power first: 8 ≤ 12 < 16, and 12 − 8 = 4, a power of two.
Answer: 12 = 8 + 4 = 1100₂. By the Proposition, taking the largest power first never needs the same power twice.
Flip the switches
- Round
- 1
- Score
- 0
- Streak
- 0
The switches show 21 = 101012. Change them to show the quotient of 21 ÷ 2. Tap a switch to turn it on (1) or off (0).
The switches are worth what their places say; check to see the total.
Counting in binary
The successor rule of lesson 1.1 is especially simple in base two, because 1 is the largest digit. To count on, change the 1s at the end of the numeral to 0s and the 0 just before them to 1: 1011₂ is followed by 1100₂, and 111₂ by 1000₂.
Let k ≥ 1. The numbers whose binary numerals have at most k bits are exactly 0, 1, 2, …, 2ᵏ − 1. So the bit strings of length k, with zeros allowed on the left, name exactly 2ᵏ different numbers.
Count up from 0 with the successor rule. A numeral gains a bit only when all its bits are 1. So all numbers up to the numeral of k ones, 11…1₂, have at most k bits, and its successor, 100…0₂ with k zeros, which is 2ᵏ, has k + 1 bits; so does every later number, since bits are never lost by counting on. The numeral of k ones names 2ᵏ − 1, because its successor is 2ᵏ.
So the numbers with at most k bits are 0, 1, …, 2ᵏ − 1, and there are 2ᵏ of them. Writing zeros on the left gives each of them a bit string of length k. Different strings name different numbers, by the uniqueness of numerals in lesson 1.1, and every string of length k names one of these numbers, so there are exactly 2ᵏ strings of length k.
A byte is a bit string of length eight.[7]
Which numbers can a byte name, and how many are they?
- By the Theorem with k = 8, the bit strings of length 8 name the numbers 0 to 2⁸ − 1.
- 2⁸ = 256, so the largest is 255 = 11111111₂ and the smallest 0 = 00000000₂.
Answer: the 256 numbers from 0 to 255.
How many digits does the binary numeral of 1,000 have?
- 2⁹ = 512 and 2¹⁰ = 1,024. So 2⁹ ≤ 1,000 < 2¹⁰.
- By the Theorem with k = 9, numerals of at most 9 bits name at most 2⁹ − 1 = 511, so 1,000 needs more than 9 bits.
- With k = 10 it needs at most 10, since 1,000 ≤ 2¹⁰ − 1 = 1,023.
Answer: 10 bits. Indeed 1,000 = 512 + 256 + 128 + 64 + 32 + 8 = 1111101000₂. In base ten the same number needs 4 digits.
Doubling and halving
In base ten, writing a 0 at the end of a numeral multiplies the number by 10 (Multiplication lesson 1.8). In every base the same thing happens with the base in place of 10.
Let n ≥ 1. Writing a 0 at the end of the numeral of n in base b gives the numeral of n × b. In particular, in base two, writing a 0 at the end doubles the number.
Let n = aₖ × bᵏ + ⋯ + a₁ × b¹ + a₀ × b⁰. Writing a 0 at the end moves every digit one place to the left, so the new numeral names aₖ × bᵏ⁺¹ + ⋯ + a₁ × b² + a₀ × b¹ + 0. Each term aᵢ × bⁱ⁺¹ equals (aᵢ × bⁱ) × b, by the rule “one more factor” and the associative property. Taking out the common factor b by the distributive property (Multiplication lesson 1.7) gives (aₖ × bᵏ + ⋯ + a₀ × b⁰) × b = n × b.
For binary numerals the textbook statement is the same: multiplying by 2 shifts the binary expansion one place to the left and adds a zero at its end.[8] Going the other way, the Lemma of lesson 1.1 says that the last bit of n is the remainder of n ÷ 2, and the other bits name the quotient. So dropping the last bit halves a number, leaving out the remainder.
10112 = 8 + 2 + 1 = 11
101102 = 16 + 4 + 2 = 22 = 2 × 11
A whole number is called even when it equals 2 × k for a whole number k, and odd when it equals 2 × k + 1.[9] These are the numbers that leave remainder 0 and remainder 1 on division by 2; Powers lesson 1.4 used the words for exponents. So a binary numeral ends in 0 exactly when its number is even, and in 1 exactly when it is odd.
45 = 101101₂. Without converting to base ten, write 2 × 45 and the quotient and remainder of 45 ÷ 2 in binary.
- 2 × 45: write a 0 at the end: 1011010₂. Check: 64 + 16 + 8 + 2 = 90.
- 45 ÷ 2: the last bit, 1, is the remainder, so 45 is odd. The other bits, 10110₂ = 16 + 4 + 2 = 22, name the quotient.
Answer: 2 × 45 = 1011010₂ = 90, and 45 = 22 × 2 + 1 with 22 = 10110₂.
Someone knows that 110₂ = 6 and concludes that 1100₂ = 60. Find the mistake.
- A 0 written at the end multiplies by the base. In base two the base is 2, not 10.
- So 1100₂ = 2 × 6 = 12. Check: 8 + 4 = 12.
Answer: 1100₂ = 12. The rule “a 0 at the end multiplies by ten” is a rule of base ten only.
Why computers use base two
The binary system suits electronic computers because a binary numeral is a string of 0s and 1s, and 0 and 1 can be held in a machine by a switch, or a similar electronic device, being off or on.[10] Base two is well suited to electronic computers, which usually tell apart only two states of a physical system.[11] Computers usually use binary notation when they do arithmetic.[12] The lesson “From calculating machines to computers” tells how this came about.
The price is length. Small bases need few different digits but make long numerals.[13] The number 2,448 takes four digits in base ten but twelve in base two.[14] People therefore rarely write long binary numerals by hand: the next lesson shows how bases 8 and 16 serve as a short way to write them.
Write 2,448 in binary and count its digits.
- The largest power of two not more than 2,448 is 2¹¹ = 2,048 (the next is 4,096). 2,448 − 2,048 = 400.
- The largest power of two not more than 400 is 256 = 2⁸ (512 is too large), leaving 144. The largest not more than 144 is 128 = 2⁷, leaving 16, which is 2⁴ itself.
- So 2,448 = 2¹¹ + 2⁸ + 2⁷ + 2⁴, with 1s in places 11, 8, 7 and 4.
Answer: 2,448 = 100110010000₂, twelve bits. Check: 2,048 + 256 + 128 + 16 = 2,448.
Exercises
Find the numbers named by (a) 110110₂; (b) 10000001₂; (c) 1111₂.
▸ Show solution
(a) 110110₂ = 32 + 16 + 4 + 2 = 54.
(b) 10000001₂ = 128 + 1 = 129.
(c) 1111₂ = 8 + 4 + 2 + 1 = 15 = 2⁴ − 1.
Write each number as a sum of different powers of two and as a binary numeral: (a) 37; (b) 64; (c) 200.
▸ Show solution
(a) 37: 32 ≤ 37 < 64; 37 − 32 = 5 = 4 + 1. So 37 = 32 + 4 + 1 = 100101₂.
(b) 64 = 2⁶ is a single power: 1000000₂.
(c) 200: 128 ≤ 200 < 256; 200 − 128 = 72; 72 − 64 = 8. So 200 = 128 + 64 + 8 = 11001000₂.
(a) Write the number after 100111₂. (b) Write the number before 10000₂.
▸ Show solution
(a) 100111₂ ends in three 1s; they become 0s and the 0 before them becomes 1: 101000₂. Check: 100111₂ = 32 + 4 + 2 + 1 = 39 and 101000₂ = 32 + 8 = 40.
(b) The number before 10000₂ = 16 is 15 = 1111₂: counting down, the four 0s become 1s and the leading 1 disappears.
(a) What is the largest number with a binary numeral of 6 bits? (b) How many different numbers can 16 bits name?
▸ Show solution
(a) By the Theorem, at most 6 bits name 0 to 2⁶ − 1 = 63; the largest is 111111₂ = 63.
(b) 16 bits name the 2¹⁶ = 65,536 numbers from 0 to 65,535 (2¹⁶ = 2⁸ × 2⁸ = 256 × 256 = 65,536).
Let n = 1011011₂. Without finding n first, write 2n and the quotient and remainder of n ÷ 2 in binary. Then check in base ten.
▸ Show solution
2n: write a 0 at the end, 10110110₂. The quotient of n ÷ 2: drop the last bit, 101101₂; the remainder is the dropped bit, 1, so n is odd.
Check: n = 64 + 16 + 8 + 2 + 1 = 91; 10110110₂ = 128 + 32 + 16 + 4 + 2 = 182 = 2 × 91; and 101101₂ = 45, with 45 × 2 + 1 = 91.
Use binary numerals to prove that 1 + 2 + 4 + ⋯ + 2ᵏ⁻¹ = 2ᵏ − 1 for every k ≥ 1. Check it for k = 5.
▸ Show solution
The sum 1 + 2 + 4 + ⋯ + 2ᵏ⁻¹ is the expansion of the binary numeral of k ones, which names 2ᵏ − 1 by the Theorem on k bits (its successor is 1 followed by k zeros, 2ᵏ). For k = 5: 1 + 2 + 4 + 8 + 16 = 31 = 2⁵ − 1.
Prove that a whole number n ≥ 1 is a power of two exactly when its binary numeral contains exactly one 1. Is 96 a power of two?
▸ Show solution
If n = 2ᵏ, its binary numeral is 1 followed by k zeros: exactly one 1. Conversely, a binary numeral with exactly one 1, in place k, names 2ᵏ. Since every number has only one binary numeral, a number is a power of two exactly when its numeral has exactly one 1.
Example: 96 = 1100000₂ has two 1s, so 96 is not a power of two; 128 = 10000000₂ is.
Summary
- The binary system is base two. Its digits, the bits, are 0 and 1; place k is worth 2ᵏ: 1, 2, 4, 8, 16, ….
- Every whole number n ≥ 1 is a sum of different powers of two in exactly one way, and its binary numeral has a 1 at each of those powers. Taking the largest power first finds them.
- Counting on in binary turns the final 1s into 0s and the 0 before them into 1. Strings of k bits name exactly the 2ᵏ numbers 0 to 2ᵏ − 1; a byte, 8 bits, names 0 to 255.
- A 0 written at the end of a numeral in base b multiplies by b: in binary it doubles. The last bit is the remainder of n ÷ 2, so it tells whether n is even or odd.
- Computers use base two because a switch has two states. Binary numerals are long: 2,448 needs twelve bits.
Sources
- 1.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 4, “The Theory of Congruences”, section 4.3, “Binary and Decimal Representations of Integers”, p. 70 (the whole topic: pp. 69–70).
“The simplest case occurs when the base b = 2, and the resulting system of enumeration is called the binary number system (from the Latin binarius, two).”
Used for: base 2 gives the binary number system, from the Latin binarius, “two”. - 2.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.2, “Representations of Integers”): “Binary Expansions”, p. 260 (the whole topic: pp. 260–261).
“In binary notation each digit is either a 0 or a 1.”
Used for: the only digits of binary notation are 0 and 1. - 3.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 1, “The Foundations: Logic and Proofs”, section 1.1, “Propositional Logic” (1.1.6, “Logic and Bit Operations”), p. 12 (the whole topic: pp. 12–13).
“A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one). This meaning of the word bit comes from binary digit, because zeros and ones are the digits used in binary representations of numbers.”
Used for: a bit is a symbol with the two values 0 and 1, and the word is short for binary digit. - 4.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 1, “The Foundations: Logic and Proofs”, section 1.1, “Propositional Logic” (1.1.6, “Logic and Bit Operations”), Definition 7, p. 12 (the whole topic: pp. 12–13).
“A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string.”
Used for: a row of bits is a bit string; its length is the number of bits. - 5.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.2, “Representations of Integers”): “Binary Expansions”, p. 260 (the whole topic: pp. 260–261).
“In other words, the binary expansion of an integer is just a bit string.”
Used for: the binary numeral of a number is a bit string. - 6.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 4, “The Theory of Congruences”, section 4.3, “Binary and Decimal Representations of Integers”, p. 70 (the whole topic: pp. 69–70).
“means that every positive integer is expressible in exactly one way as a sum of distinct powers of 2.”
Used for: the Theorem: every positive whole number is a sum of different powers of two in exactly one way. - 7.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.2, “Representations of Integers”: “Octal and Hexadecimal Expansions”), p. 261 (the whole topic: pp. 261).
“Bytes, which are bit strings of length eight, can be represented by two hexadecimal digits.”
Used for: the definition of a byte: a bit string of length eight. - 8.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.3, “Algorithms for Integer Operations”: “Multiplication Algorithm”), p. 265 (the whole topic: pp. 265–266).
“Each time we multiply a term by 2, we shift its binary expansion one place to the left and add a zero at the tail end of the expansion.”
Used for: multiplying by 2 shifts the binary numeral one place to the left and adds a 0 at its end. - 9.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 1, “The Foundations: Logic and Proofs”, section 1.7, “Introduction to Proofs” (1.7.5, “Direct Proofs”), Definition 1, p. 86 (the whole topic: pp. 86).
“The integer n is even if there exists an integer k such that n = 2k, and n is odd if there exists an integer k such that n = 2k + 1.”
Used for: the definitions of even and odd numbers. - 10.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 4, “The Theory of Congruences”, section 4.3, “Binary and Decimal Representations of Integers”, p. 70 (the whole topic: pp. 69–70).
“The binary system is most convenient for use in modern electronic computing machines, because binary numbers are represented by strings of zeros and ones; 0 and 1 can be expressed in the machine by a switch (or a similar electronic device) being either on or off.”
Used for: binary suits electronic computers: a numeral is a string of 0s and 1s, held by switches that are off or on. - 11.Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).Chapter 27, “Beyond Perfection”, p. 592 (the whole topic: pp. 592).
“the base 2 is well adapted to electronic computers which usually can recognise only two different states”
Used for: base two suits machines that tell apart only two states of a physical system (the sentence goes on: symbolised by 0 and 1). - 12.Kenneth H. Rosen, Discrete Mathematics and Its Applications (8th ed., McGraw-Hill, 2019).Chapter 4, “Number Theory and Cryptography”, section 4.2, “Integer Representations and Algorithms” (4.2.2, “Representations of Integers”), p. 260 (the whole topic: pp. 260–261).
“In particular, computers usually use binary notation (with 2 as the base) when carrying out arithmetic”
Used for: computers usually use binary notation for arithmetic. - 13.David M. Burton, Elementary Number Theory (7th ed., McGraw-Hill, 2011).Chapter 4, “The Theory of Congruences”, section 4.3, “Binary and Decimal Representations of Integers”, p. 70 (the whole topic: pp. 69–70).
“Small values of b give rise to lengthy representation of numbers, but have the advantage of requiring fewer choices for coefficients.”
Used for: small bases need few different digits (few choices for each coefficient) but make long numerals. - 14.Georges Ifrah, The Universal History of Numbers: From Prehistory to the Invention of the Computer (trans. David Bellos, E. F. Harding, Sophie Wood and Ian Monk, John Wiley & Sons, 2000).Chapter 2, “Base Numbers and the Birth of Number-Systems”, section “Advantages and Drawbacks of Base 10”, p. 41 (the whole topic: pp. 40–41).
“Now, whilst we now require only four digits to express the number two thousand four hundred and forty-eight (2,448) in a base 10 number system, a base 2 or binary system (which is in fact the system used by computers) requires no fewer than twelve digits”
Used for: 2,448 takes four digits in base ten but twelve in base two.