Ever stared at an error log full of values like FF 3A 2C and wondered what they mean? Or felt confused when you saw 0b1010 or 0xFF in code? That’s where number base conversion comes in. Computers work with binary, octal, decimal and hexadecimal in different situations, so being able to convert between bases is a practical skill for reading and writing values.

In this article, we explain the basics of number base conversion - converting between binary, octal, decimal and hexadecimal - with concrete examples and step-by-step instructions. It’s written for programming beginners, but it’s also useful if you already know the basics but can’t explain them clearly. When you’d rather not convert by hand, the free tool introduced later in this article has you covered.

What are number bases? Four ways to count

A number base is the set of rules that determine when a digit “rolls over” into a new position. The decimal system we use every day has 10 digits (0-9), so it rolls over after 9. Computers, on the other hand, process everything internally in binary (0 and 1 only).

Binary, octal, decimal and hexadecimal compared

Base Digits used Rollover example Typical use
Binary 0, 1 1 → 10 → 11 → 100 Computer internals, bit operations
Octal 0-7 7 → 10 → 11 → 12 UNIX file permissions, etc.
Decimal 0-9 9 → 10 → 11 → 12 Everyday numbers
Hexadecimal 0-9, A-F F → 10 → 11 → 12 Color codes, memory, MAC addresses

Hexadecimal uses the letters A-F (for 10-15) in addition to 0-9. For example, FF is 255 in decimal.

Did you know? Hexadecimal is often called "hex" for short. In code, binary values are usually written with a 0b prefix (e.g. 0b1010) and hexadecimal with 0x (e.g. 0xFF).

The key idea: each digit has a weight

The key to base conversion is understanding that each digit position carries a “weight”. The decimal number 123 is really 1×100 + 2×10 + 3×1, which is the same as 1×10² + 2×10¹ + 3×10⁰. In other words, the nth digit from the right has a weight of (base)^(n−1).

Apply this rule and you can convert from any base to decimal. Let’s use the binary number 1010 as an example.

Digit position 2³ 2² 2¹ 2⁰
Weight (decimal) 8 4 2 1
Binary digit 1 0 1 0
  • 1×8 + 0×4 + 1×2 + 0×1 = 10

So binary 1010 equals decimal 10.

How to convert from decimal to binary

To convert a decimal number to binary, divide by 2 repeatedly and collect the remainders. Let’s convert the decimal number 42.

Calculation Quotient Remainder
42 ÷ 2 21 0
21 ÷ 2 10 1
10 ÷ 2 5 0
5 ÷ 2 2 1
2 ÷ 2 1 0
1 ÷ 2 0 1

Read the remainders from bottom to top: 101010. So decimal 42 is binary 101010.

Grouping tip: Binary is easier to read when grouped in fours, and hex in twos. Example: 101010 → 0010 1010. Each group of four binary digits maps to exactly one hex digit.

Binary to hex: just group by fours

Converting between binary and hexadecimal is the most common conversion in programming - and it needs no calculation at all. Just split the binary number into groups of four digits and look them up in the table below. Four binary digits can represent 0-15, which is exactly one hex digit.

The conversion table

Binary (4 digits) Hex Binary (4 digits) Hex
0000 0 1000 8
0001 1 1001 9
0010 2 1010 A
0011 3 1011 B
0100 4 1100 C
0101 5 1101 D
0110 6 1110 E
0111 7 1111 F

Example: 101010 to hex

  1. Split into groups of four: 0010 1010 (pad with leading zeros if needed)
  2. Replace each group: 0010 → 2, 1010 → A
  3. Result: 2A

Going the other way, convert each hex digit into its four-digit binary equivalent. 3F → 0011 1111 → 111111 (drop the leading zeros).

Note: A common mistake is miscounting digit positions when converting binary to decimal. Remember the rightmost digit has weight 2⁰ (= 1). Also, uppercase and lowercase A-F are equivalent in hex.

When you’ll need base conversion in practice

Base conversion isn’t just an exam topic - it shows up constantly in real work.

  • Debugging code: Deciphering the hex values that fill memory dumps and error logs
  • Bit operations: Managing flags and masks means thinking in binary digits
  • Color codes: Matching #FF8800 to its decimal RGB values (255, 136, 0)
  • Networking and device config: Relating MAC addresses (hex) to IP addresses (decimal)
  • UNIX permissions: In chmod 755, the 7 is binary 111 (read, write and execute)

Learning tip: Don't try to memorize everything at once. Start with hex values 0-15 and the powers of two (1, 2, 4, 8, 16, 32, 64, 128, 256). With those two sets, you can do many conversions mentally.

Using the base converter tool

Once you understand the math, let a tool handle the actual conversion. The Tools Hub number base converter instantly converts between binary, octal, decimal and hexadecimal as you type.

1

Enter a number

Type the number you want to convert (e.g. `101010`) and choose its base (e.g. binary).

2

Check the other bases

The decimal, hex and octal equivalents appear automatically.

3

Copy and use

Copy the value you need and paste it straight into your code or documentation.

Tool mentioned in this article

Number Base Converter

Convert between binary, octal, decimal and hexadecimal. Exact results even for huge integers.

Try it now

Summary

  • A number base is the rule for when digits roll over; binary, octal, decimal and hex are all in use
  • To convert to decimal, multiply each digit by its weight (a power of the base) and add them up
  • To convert decimal to binary, divide by 2 repeatedly and read the remainders from bottom to top
  • Binary to hex is just grouping digits by fours and using the lookup table
  • Hex letters A-F stand for 10-15, so FF = 255
  • For checking your hand calculations, the Tools Hub base converter is handy

Base conversion feels intimidating at first, but the four-digit table and the powers of two make it much more approachable. If your answer doesn’t match, verify it with the tool.

FAQ

What’s the easiest way to convert binary to hex?

Split the binary number into groups of four digits from the right, then replace each group with its hex equivalent using the table. For example, 101010 becomes 0010 1010, which is 2A. To go the other way, convert each hex digit into four binary digits.

How do I convert decimal to binary?

Divide by 2 repeatedly and record the remainders, then read them from bottom to top. For example, 42 produces remainders that read 101010 from bottom to top, so 42 is 101010 in binary.

What do the hex letters A-F mean?

They represent the values 10-15: A=10, B=11, C=12, D=13, E=14, F=15. For example, FF is 255 in decimal.

Can I convert numbers with decimals?

The Tools Hub converter handles integers only; input with a decimal point is rejected with an error. For fractional values, you can convert by hand: repeatedly multiply the fractional part by 2 (or 16) and record the integer parts.

References