Skip to content
Brainlag

Number base converter

Convert between binary, denary, hexadecimal and octal, with the working written out, plus two's complement in 8, 16 and 32 bits. For GCSE and A-level Computer Science.

Learn this properly

Lessons from the Computer Science course on this topic: worked steps, then exam-style questions with new numbers every time.

See the whole course

Formulas

Place valuea number in base b is the sum of each digit × b to the power of its place, counting places from 0 on the right
Hex digitsA = 10, B = 11, C = 12, D = 13, E = 14, F = 15

Worked example

Convert 45 to binary and to hexadecimal.

  1. Divide by 2 and keep the remainders: 45 → 22 r 1, 22 → 11 r 0, 11 → 5 r 1, 5 → 2 r 1, 2 → 1 r 0, 1 → 0 r 1.
  2. Read the remainders from the bottom up: 101101.
  3. Check: 32 + 8 + 4 + 1 = 45.
  4. For hex, 45 = 2 × 16 + 13, and 13 is D.

Answer: 45 = 101101 in binary and 2D in hexadecimal.

Common mistakes

  • Reading the remainders from the top down, which writes the binary number backwards.
  • Counting place values from 1 instead of 0: the rightmost digit is worth b0 = 1.
  • Writing 10 to 15 as two digits in hex instead of A to F.
  • Dropping leading zeros when a fixed width is asked for, such as 8 bits: 45 is 00101101.

How it works

This converter turns a whole number into binary, octal, decimal and hexadecimal at once, and into any base from 2 to 36 if you need one. It writes out the working the way a GCSE or A-level Computer Science answer expects: place values to get into decimal, repeated division to get out of it, and groups of four bits for hex. It also shows how the number sits in 8, 16, 32 or 64 bits, including two's complement for negative numbers.

  1. Type the number in the Number box. Spaces and underscores are ignored, so 1011 0110 is fine.
  2. Choose the base it is written in: decimal, binary, hexadecimal, octal or another base. Code prefixes work too: 0b101101, 0x2D and 0o55 switch the base for you.
  3. Open the working to see each step: place values into decimal, division by 2 or 16 out of decimal, or four-bit groups between binary and hex.
  4. For a negative decimal number, the In bits section gives its two's complement in the smallest size that holds it.

Tips

  • Learn the place values of an 8-bit byte by heart: 128, 64, 32, 16, 8, 4, 2, 1. Most exam conversions only need those.
  • Each hex digit is exactly four bits, so binary to hex never needs decimal in between: split into fours from the right and convert each group.
  • If an 8-bit answer starts with 1, it means something different as a signed number. The In bits section shows both readings.
  • Check your own working by typing your answer back in with its base: the decimal line should match where you started.

FAQ

How do I convert binary to decimal?
Write the place values over the bits, starting with 1 on the right and doubling each time to the left. Add the place values that have a 1 under them. 101101 is 32 + 8 + 4 + 1 = 45. The working section lays this out for any number you type.
How do I convert decimal to binary?
Divide by 2 and write down the remainder, then divide the answer by 2 again, until you reach 0. The remainders read from the bottom up are the binary number. The converter shows every division.
What is two's complement?
It is how computers store negative whole numbers. To find it, write the positive number in binary, flip every bit, then add 1. In 8 bits, -1 is 11111111 and -128 is 10000000.
Why does my number say it is too big for 8 bits?
An unsigned 8-bit number can only go up to 255, because 8 bits give 256 patterns. Anything larger needs more bits, and in a program it would overflow. The converter tells you how many bits the number really needs.
Does it handle very large numbers?
Yes. It works with whole numbers of up to 300 digits exactly, with no rounding. For very long numbers it gives the answer without writing out every step.