Electrical Engineering › Section R · Digital concepts, number systems, and codes › Topic R.4
Binary numbers, conversion, and arithmetic
Every number inside a digital system is stored in binary, a place-value system with only two digits. This topic shows how binary weights work, how to convert between binary and decimal in both directions, fractions included, and how to add, subtract, multiply and divide in base 2.
Place value with base ten
Decimal is a positional system: each digit is multiplied by a power of ten that depends on its column, its weight. In 472.5 the weights are \(10^2\), \(10^1\), \(10^0\) and \(10^{-1}\), so the value is \(4 \times 100 + 7 \times 10 + 2 \times 1 + 5 \times 0.1\). Binary works the same way with base 2 and only the digits 0 and 1. To avoid confusion when bases are mixed, this course writes the base as a subscript: \(101_2\) is five, while \(101_{10}\) is one hundred and one.
Binary weights and counting
Binary weights are powers of two: from the binary point leftward they are 1, 2, 4, 8, 16, 32, 64, 128 and so on, and to the right 0.5, 0.25, 0.125, 0.0625. The rightmost bit of a whole number is the least significant bit (LSB) and the leftmost the most significant bit (MSB). Counting in binary runs 0, 1, 10, 11, 100, 101, 110, 111: the LSB flips on every count, the next bit every second count, the next every fourth. With \(n\) bits you can count from 0 up to \(2^n - 1\), so 8 bits reach 255 and 10 bits reach 1023.
Binary to decimal
To convert binary to decimal, add the weights of the bits that are 1. For \(101101_2\), the 1s sit at weights 32, 8, 4 and 1, so the value is \(32 + 8 + 4 + 1 = 45_{10}\). Fractions work the same way with negative powers. For \(1101.011_2\), the whole part gives \(8 + 4 + 1 = 13\) and the fraction gives \(0.25 + 0.125 = 0.375\), so the value is \(13.375_{10}\). Write the weights above the bits before you start: it prevents the most common slip, starting the weights from the wrong end.
Decimal to binary: sum of weights
To go the other way for small numbers, find the largest power of two that fits, subtract it, and repeat with the remainder. For 83: the largest weight not over 83 is 64, leaving 19; then 16, leaving 3; then 2, leaving 1; then 1, leaving 0. The weights used are 64, 16, 2 and 1, so put 1s in those columns and 0s elsewhere: \(83_{10} = 1010011_2\). Check by adding the weights back: \(64 + 16 + 2 + 1 = 83\). The method is quick by eye but becomes error-prone for large numbers.
Worked example: repeated division by 2
Convert \(83_{10}\) to binary by repeated division, the systematic method. 1. Divide by 2 and record each remainder: 83 gives 41 remainder 1; 41 gives 20 r 1; 20 gives 10 r 0; 10 gives 5 r 0; 5 gives 2 r 1; 2 gives 1 r 0; 1 gives 0 r 1. 2. Stop when the quotient reaches 0. 3. The first remainder is the LSB and the last is the MSB, so read the remainders from last to first: 1010011. 4. Check: the result matches the sum-of-weights answer, \(83_{10} = 1010011_2\). Reading the remainders in the order found would give 1100101, which is 101, wrong.
Decimal fractions to binary
For the fractional part, multiply by 2 repeatedly; each time the whole-number part of the product, 0 or 1, is the next bit after the binary point, and the fractional part carries on. For 0.6875: \(\times 2 = 1.375\) gives 1; \(0.375 \times 2 = 0.75\) gives 0; \(0.75 \times 2 = 1.5\) gives 1; \(0.5 \times 2 = 1.0\) gives 1 and stops. So \(0.6875_{10} = 0.1011_2\). Many decimal fractions never stop: 0.3 becomes 0.0100110011..., repeating forever, so a computer must round it. That is why 0.1 and 0.3 are not stored exactly in binary.
Binary addition
Binary addition follows four rules: \(0 + 0 = 0\), \(0 + 1 = 1\), \(1 + 1 = 10_2\) (sum 0, carry 1) and \(1 + 1 + 1 = 11_2\) (sum 1, carry 1), the last when a carry arrives in a column that already has two 1s. Add column by column from the LSB, exactly as in decimal.
Check in decimal: \(11 + 7 = 18\), and \(10010_2 = 16 + 2 = 18\). The sum of two 4-bit numbers can need 5 bits.
Worked example: binary subtraction
Subtract \(01101_2\) from \(11010_2\). The rules are \(0 - 0 = 0\), \(1 - 0 = 1\), \(1 - 1 = 0\) and \(0 - 1 = 1\) with a borrow of 1 from the next column. 1. Column 1 (LSB): \(0 - 1\), borrow, giving 1. 2. Column 2: \(1 - 0 - 1\) (the borrow) \(= 0\). 3. Column 3: \(0 - 1\), borrow, giving 1. 4. Column 4: \(1 - 1 - 1\) needs a borrow: \(1 + 2 - 1 - 1 = 1\). 5. Column 5: \(1 - 0 - 1 = 0\). The result is \(01101_2\). Check: \(26 - 13 = 13\), and \(1101_2 = 13\). "Complements and signed numbers" shows how hardware does this with an adder.
Multiplication and division
Binary multiplication is easier than decimal, because each partial product is either 0 or a shifted copy of the multiplicand. For \(1101_2 \times 101_2\): the multiplier's 1s are in the first and third places, so add 1101 and 1101 shifted two places, 110100: \(1101 + 110100 = 1000001_2\). Check: \(13 \times 5 = 65 = 64 + 1\). Division is long division in which each trial step either subtracts the divisor or does not. For \(11011_2 \div 11_2\) the quotient is \(1001_2\) with no remainder: \(27 \div 3 = 9\).
Common mistakes to avoid
First, reading the remainders of repeated division top to bottom: the first remainder is the LSB. Second, numbering weights from the left: weights grow from the binary point outward, starting with 1 at the LSB. Third, forgetting the carry when \(1 + 1 + 1\) appears in one column; it gives sum 1, carry 1. Fourth, assuming every decimal fraction has a short binary form: 0.3 repeats forever. Fifth, forgetting that n bits stop at \(2^n - 1\), not \(2^n\): 8 bits reach 255, not 256.
Key takeaways
Binary is positional with weights that are powers of 2: 1, 2, 4, 8 to the left of the point and 0.5, 0.25, 0.125 to the right. Bases are written as subscripts, as in 1011₂ and 47₁₀. Binary to decimal: add the weights of the 1s. Decimal to binary: sum of weights, or repeated division by 2 read from the last remainder up; fractions by repeated multiplication by 2. n bits count from 0 to 2ⁿ − 1. Addition uses 1 + 1 = 10₂ with carries, subtraction uses borrows, multiplication adds shifted copies and division repeats subtraction.
Flashcards
Flashcard
Shows a number's base, as in 101₂ = 5₁₀
Test your understanding
Question 1 of 5
What is 110110₂ in decimal?
Question 2 of 5
Converting 37₁₀ by repeated division by 2 gives the remainders 1, 0, 1, 0, 0, 1 in that order. What is 37 in binary?
Question 3 of 5
What is 1110₂ + 0111₂?
Question 4 of 5
What is 0.625₁₀ in binary?
Question 5 of 5
What is the largest whole number a 10-bit binary register can hold?
