Skip to content
All subjects

ComputerArchitecture.

Learn how binary values, logic gates, and circuits build the arithmetic core of a processor.

Modules
5
Topics
27
Bits moving through an arithmetic logic unitTwo four-bit inputs enter an ALU. A control signal selects the operation, and a four-bit result leaves the unit.10111110ALUADD · AND · XORCONTROL0111OPERAND AOPERAND BRESULT

0 of 27 complete

Contents

Binary Numbers and Place Value

A computer stores information using two stable states. We write these states as 0 and 1. One binary digit is called a bit, and a group of eight bits is called a byte.

Why Binary Uses Powers of Two

Decimal has ten digits, so its place values are powers of 10. Binary has only two digits, so its place values are powers of 2.

Starting from the right, the binary place values are 1, 2, 4, 8, 16, 32, and so on. A 1 means the place value is included. A 0 means it is not included.

Binary place-value diagram converting 10110101 into decimal 181 by adding the active powers of two.
Each bit either includes or excludes its place value.

Binary to Decimal

Multiply each bit by its place value and add the results. For 10110101, the active places are 128, 32, 16, 4, and 1.

The symbol Σ means add all the terms. In the positional formula, bitᵢ is either 0 or 1, and 2ⁱ is the place value at position i.

Bit position76543210
Place value1286432168421
Bit in 1011010110110101
Positional value
Value=(biti×2i)\mathrm{Value}=\sum \left(\mathrm{bit}_{i}\times 2ⁱ\right)

The rightmost bit uses i = 0.

Example
101101012=128+32+16+4+1=1811010110101_{2}=128+32+16+4+1=181_{10}

Decimal to Binary

Repeatedly divide the decimal number by 2. Record each remainder. Read the remainders from bottom to top.

Divide by 2
Record remainder
Use the quotient again
Stop at quotient 0
Read upward

Unsigned Range and Bit Width

An unsigned value uses every bit for magnitude. With n bits, there are 2ⁿ different patterns. The smallest pattern is all 0s and the largest is all 1s.

Bit width
Unsigned range
4 bits
0 to 15
8 bits
0 to 255
16 bits
0 to 65,535
Number of patterns
Patterns=2n\mathrm{Patterns}=2^{n}
Unsigned n-bit range
0 to 2n10\ \mathrm{to}\ 2^{n}-1

Worked Problems

Write the place values or division steps. This makes the method easy to check and earns method marks in an exam.

Problem 01

Convert binary to decimal

Convert 110101₂ to decimal.

  1. 01Write place values: 32, 16, 8, 4, 2, 1.
  2. 02Keep the places whose bit is 1: 32, 16, 4, 1.
  3. 03Add them: 32 + 16 + 4 + 1 = 53.

Answer

110101₂ = 53₁₀

Problem 02

Convert decimal to binary

Convert 45₁₀ to binary.

  1. 0145 ÷ 2 = 22 remainder 1
  2. 0222 ÷ 2 = 11 remainder 0
  3. 0311 ÷ 2 = 5 remainder 1
  4. 045 ÷ 2 = 2 remainder 1
  5. 052 ÷ 2 = 1 remainder 0
  6. 061 ÷ 2 = 0 remainder 1
  7. 07Read the remainders from bottom to top: 101101.

Answer

45₁₀ = 101101₂

Problem 03

Convert a larger value and check it

Convert 173₁₀ to 8-bit binary and verify the result.

  1. 01Choose the largest place not above 173: 128. Remainder = 45.
  2. 02Skip 64. Use 32, leaving 13. Use 8, leaving 5. Use 4, leaving 1. Skip 2 and use 1.
  3. 03Write the bits under 128, 64, 32, 16, 8, 4, 2, 1: 10101101.
  4. 04Check: 128 + 32 + 8 + 4 + 1 = 173.

Answer

173₁₀ = 10101101₂

How to read an unsigned binary number

  1. 01Write powers of two above the bits, starting with 2⁰ on the right.
  2. 02Select every place whose bit is 1.
  3. 03Add the selected place values.
  4. 04Check that the answer is inside the range for the bit width.

Example

Why 8 bits stop at 255

Eight bits create 2⁸ = 256 patterns. Because counting starts at 0, the values are 0 through 255, not 1 through 256.

A common mistake

The leftmost bit is not always a sign bit. It is a sign bit only when the chosen representation is signed.

Actions for Binary Numbers and Place Value