9.4 Converting Between Binary and Decimal

COS2621 - Computer Organisation · 9. Number Systems

Converting Between Binary and Decimal

Understanding Binary and Decimal Systems

The binary system uses only two digits: 0 and 1. Each digit in a binary number represents a power of 2. The decimal system, which is more familiar, uses ten digits: 0 through 9. Each digit in a decimal number represents a power of 10.

Converting Decimal to Binary

To convert a decimal number to binary, you can use the division-by-two method. This involves dividing the decimal number by 2 and recording the remainder. Repeat this process until the quotient is 0. The binary number is then read from the bottom remainder to the top.

**Example:** Convert decimal 13 to binary.

  1. 13 divided by 2 is 6, remainder 1.
  2. 6 divided by 2 is 3, remainder 0.
  3. 3 divided by 2 is 1, remainder 1.
  4. 1 divided by 2 is 0, remainder 1.

Reading the remainders from bottom to top gives us 1101. Thus, decimal 13 is binary 1101.

Converting Binary to Decimal

To convert a binary number to decimal, you multiply each digit by 2 raised to the power of its position, counting from right to left starting at 0. Then, add all these values together.

**Example:** Convert binary 1101 to decimal.

  1. 1 × 2^3 = 8
  2. 1 × 2^2 = 4
  3. 0 × 2^1 = 0
  4. 1 × 2^0 = 1

Add these values: 8 + 4 + 0 + 1 = 13. Thus, binary 1101 is decimal 13.

Common Mistakes

Watch out: Ensure you keep track of the position of binary digits when converting to decimal. A common mistake is to miscalculate the power of 2 for each digit.

Practice Problems

1. Convert decimal 25 to binary.

2. Convert binary 10101 to decimal.

Using Hexadecimal Notation

Hexadecimal notation is another number system that is base 16. It uses digits 0-9 and letters A-F. Each hexadecimal digit can represent four binary digits (bits). This makes it easier to read and write large binary numbers.

To convert from hexadecimal to decimal, multiply each digit by 16 raised to the power of its position, similar to binary and decimal conversions.

**Example:** Convert hexadecimal 1A3 to decimal.

  1. 1 × 16^2 = 256
  2. A (10) × 16^1 = 160
  3. 3 × 16^0 = 3

Add these values: 256 + 160 + 3 = 419. Thus, hexadecimal 1A3 is decimal 419.

Summary

  • Binary uses 0 and 1; decimal uses 0-9.
  • To convert decimal to binary, use division by 2.
  • To convert binary to decimal, multiply by powers of 2.
  • Hexadecimal is base 16 and simplifies binary representation.

Check your understanding

  • Convert decimal 30 to binary.
  • Convert binary 1110 to decimal.
  • Convert hexadecimal 2F to decimal.
  • What is the binary equivalent of decimal 255?

Test yourself

4 quick questions on this lesson. Pick an answer to see if you're right.

  1. 1. What is the binary representation of the decimal number 25?

  2. 2. Which of the following is the correct decimal value for the binary number 10101?

  3. 3. Which method is used to convert a decimal number to binary?

  4. 4. What is the hexadecimal representation of the decimal number 419?