Binary, decimal and hex: converting by hand
Learn the method, check each answer with the tool, and see why hex shows up in colors, hashes, file permissions and character codes.
To convert binary to decimal, add up the powers of two at every position holding a 1; to get hexadecimal, group the bits in fours and write one digit per group. The binary, decimal and hex converter checks each answer instantly: type a value in one base and the others update, all in your browser. Knowing the method pays off beyond exams, since it explains character codes, file permissions, colors and hashes.
What is a number base?
We count in decimal, base 10, with ten digits, and each position is worth ten times the previous one. Binary (base 2) has just 0 and 1, and each position doubles. Hexadecimal (base 16) has sixteen digits, 0 to 9 and a to f, and each position is worth sixteen times the last. Octal (base 8) uses the digits 0 to 7.
Binary to decimal, step by step
Take 10110110. Write each position's value from right to left: 1, 2, 4, 8, 16, 32, 64, 128. Add the positions that hold a 1:
- The positions with a 1 are 128, 32, 16, 4 and 2.
- 128 + 32 + 16 + 4 + 2 = 182.
So 10110110 in binary is 182 in decimal.
Decimal to binary
Divide by 2 repeatedly and write the remainders from bottom to top. For 203 the result is 11001011. In octal it's 313 and in hexadecimal cb. A quick check is to type 203 into the converter's decimal field and read the other three.
Binary to hex: four bits at a time
One hex digit equals exactly 4 bits, so you convert by grouping. 10110110 splits into 1011 and 0110. The first group is 11, written b, and the second is 6. The result is b6. The tool has a group-in-nibbles option so you can see those blocks.
That is why hex is everywhere: it's a compact way to write bytes. A byte is 8 bits, which is two hex digits, and 00 to ff covers 256 values, the same as 0 to 255.
Three places you'll meet it
- ASCII and text. The capital letter A has the code 65, which is
41in hex and01000001in binary. Seeing character codes in hex is routine in encoding bugs and in URL encoding, where%41stands for A. - File permissions. On Unix-like systems
755is octal. In binary it's111 101 101, meaning read, write and execute for the owner, and read and execute for everyone else. - Colors and hashes. The color
#3b82f6is three bytes in hex:3bis 59,82is 130 andf6is 246, as HEX vs RGB vs HSL shows. A SHA-256 hash is 64 hex characters, so 256 bits, as discussed in MD5 vs SHA-256.
How to use the converter
- Open the converter and type a value into any of the four fields: binary, octal, decimal or hexadecimal. The others update.
- If your number has a prefix (
0xfor hex,0bfor binary,0ofor octal), the tool recognizes it when it matches the base. It also ignores spaces and underscores used for grouping, and accepts a negative sign. - Switch on Group in nibbles to read binary in blocks.
- For other bases, use the arbitrary base section, from 2 to 36, with a source and a target base. In base 36, for example,
zzis 1295. - Check the quick reference table for 0 to 16.
One technical advantage: the tool computes with arbitrary-size integers, so a huge number such as a 64-character hash goes back and forth without losing a single digit. Ordinary floating-point arithmetic in many languages loses precision beyond a certain size.
Try three on your own
Convert 45 to binary, 2f to decimal and 11111111 to hex, then check them in the tool. The answers are 101101, 47 and ff. The last one is the largest value a single byte can hold, 255, which is why you see ff so often.
Mistakes people make by hand
- Counting positions left to right instead of right to left.
- Forgetting that in hex
ais 10,bis 11 and so on up tof, which is 15. - Confusing bases:
10can be ten, two or sixteen depending on where you are. - Grouping bits from the left. Group from the right, and pad the leftmost group with zeros if it comes up short.
When in doubt, write the base with a prefix or a subscript.
Frequently asked questions
How do I convert binary to decimal?
Write each position's value from right to left (1, 2, 4, 8, 16...) and add the positions holding a 1. For example, 10110110 is 128 + 32 + 16 + 4 + 2, which gives 182.
How do I convert binary to hexadecimal?
Group the bits in fours from the right and write one hex digit per group. 1011 is b and 0110 is 6, so 10110110 is b6.
Why is hexadecimal so common in computing?
Because each digit equals 4 bits, so it writes bytes compactly: two digits per byte.
What does 0x mean before a number?
A prefix saying the number is in hexadecimal. 0b means binary and 0o means octal.
Can I convert to any base?
Yes, from 2 to 36, using the digits 0 to 9 and the letters a to z.
Convert between bases
Linked binary, octal, decimal and hex fields, plus any base from 2 to 36. Runs locally, free, no signup.
Open Base Converter →Related tools
- Base Converter: binary, octal, decimal and hex, plus bases 2 to 36.
- Hash Generator: hashes are written in hexadecimal.
- Color Converter: a HEX color is three bytes in hexadecimal.
- Base64: another way to represent bytes as text.
You might also like: what is Base64? Encoding explained in plain English and Unix timestamp explained and the 2038 problem.