PyGCSE Python Lab

Number Base Converter

Convert between decimal, binary, and hexadecimal with full working shown at every step. Covers AQA A Level CS (7517) §4.5.1–4.5.2.

📖 Learn Step-by-Step
42 (Decimal)=101010(Binary)
Decimal
42
Binary
101010
Hexadecimal
2A

Step-by-step working

Input is already decimal: 42
Convert decimal 42 to binary (repeated division by 2):
42 ÷ 2 = 21 remainder 0
21 ÷ 2 = 10 remainder 1
10 ÷ 2 = 5 remainder 0
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Read remainders bottom→top: 101010

Number Base Practice Questions

Use the converter above to check your working, then try these exam-style questions.

Q1Convert binary to denary
0/1 mark

Given Binary Number:

1286432168421
11010110

Your Answer (Denary):

Q2Convert denary to binary
0/1 mark

Given Denary Number:

173

Your Answer (Binary):

1286432168421
Q3Convert binary to hexadecimal
0/1 mark

Given Binary Number:

1286432168421
10111110

Your Answer (Hexadecimal):

1286432168421
Hex
Q4Convert hexadecimal to binary
0/1 mark

Given Hexadecimal: A3

Your Answer (Binary):

1286432168421
Binary
Nibble:
(8421)
(8421)
Hex
Q5Convert hexadecimal to denary
0/2 marks

Given Hexadecimal: 3F

Working (optional — convert to binary first):

1286432168421
Binary
Nibble:
(8421)
(8421)
Hex

Your Answer (Denary):

Q6Convert denary to hexadecimal
0/2 marks

Given Denary Number:

200

Working (convert to binary, then to hex):

1286432168421
Binary
Nibble:
(8421)
(8421)
Hex
Quick reference — number bases

Decimal (base 10):

  • Uses digits 0–9
  • Each position is a power of 10 (units, tens, hundreds…)

Binary (base 2):

  • Uses digits 0 and 1
  • Each position is a power of 2 (1, 2, 4, 8, 16, 32, 64, 128…)
  • Computers use binary because transistors have two states

Hexadecimal (base 16):

  • Uses 0–9 and A–F (A=10, B=11, C=12, D=13, E=14, F=15)
  • Each hex digit represents exactly 4 binary bits (a nibble)
  • Used for memory addresses, colour codes, MAC addresses

Conversion methods:

  • Binary → Decimal: sum the place values where bit = 1
  • Decimal → Binary: repeated division by 2, read remainders bottom→top
  • Binary ↔ Hex: group 4 bits per hex digit
  • Decimal → Hex: repeated division by 16