How to Convert Binary to Decimal and Hex
Computers store numbers in binary (base 2). People use decimal (base 10), and programmers often use hexadecimal (base 16). Converting between them is easy once you know place values.
On this page 2 min read
Number systems in brief
- Binary uses only the digits 0 and 1.
- Octal uses the digits 0 to 7.
- Decimal uses the digits 0 to 9.
- Hexadecimal uses 0 to 9 and the letters A to F, where A is 10 and F is 15.
Binary to decimal
Each binary digit has a place value that doubles from right to left: 1, 2, 4, 8, 16, 32, 64, 128. Add up the place values where the digit is 1.
Example: binary 1101 = 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 = 8 + 4 + 0 + 1 = 13.
Example: binary 10110 = 16 + 0 + 4 + 2 + 0 = 22.
Decimal to binary
Divide the number by 2 again and again, and write down each remainder. Then read the remainders from the bottom to the top.
Example: 25 / 2 = 12 remainder 1. 12 / 2 = 6 remainder 0. 6 / 2 = 3 remainder 0. 3 / 2 = 1 remainder 1. 1 / 2 = 0 remainder 1. Reading upward gives 11001.
Binary to hexadecimal
Group the binary digits in fours, starting from the right, and convert each group to one hex digit.
Example: 11010111 splits into 1101 and 0111. 1101 is 13, which is D, and 0111 is 7. So the hex value is D7, which equals 215 in decimal.
Hexadecimal to decimal
Hex place values are powers of 16: 1, 16, 256 and so on. Example: 2F = 2 x 16 + 15 = 47. And FF = 15 x 16 + 15 = 255.
Quick reference
Decimal = binary = hex: 8 = 1000 = 8, 9 = 1001 = 9, 10 = 1010 = A, 11 = 1011 = B, 12 = 1100 = C, 13 = 1101 = D, 14 = 1110 = E, 15 = 1111 = F.
Where you will see these
- Color codes such as #FF0000 use hex pairs for red, green and blue.
- Memory addresses and error codes are often written in hex.
- Network masks and file permissions are easier to understand in binary.
Check your work
Type a number into the Binary, Hex and Decimal Converter and choose its base. It shows the binary, octal, decimal and hex values together.