Skip to main content

Number Base Converter

Convert between binary, octal, decimal, hexadecimal and any base from 2 to 36.

Binary is base 2, octal base 8, decimal base 10 and hexadecimal base 16. Decimal 255 is 11111111 in binary, 377 in octal and FF in hexadecimal.

By Piero Nanni · Last checked

Number Base Converter

Binary

Octal

Decimal

Hexadecimal

A base is how many digits a system has before it carries. Decimal has ten, so after 9 it carries to 10. Binary has two, so after 1 it carries to 10, which means two. The digits themselves are just labels for place values that are powers of the base: in binary the places are 1, 2, 4, 8, 16; in hexadecimal they are 1, 16, 256, 4096.

Hexadecimal exists because sixteen is two to the fourth, so each hex digit is exactly four binary digits with no remainder. That makes hex a compact way of writing binary that a person can read: 11111111 becomes FF, and a 32-bit value fits in eight characters. Octal plays the same role for three bits at a time, which is why Unix file permissions are octal.

Counting in four bases

Counting in four bases
DecimalBinaryOctalHexadecimal
0000
1111
21022
31133
410044
510155
611066
711177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F
16100002010

Values worth recognising

Values worth recognising
DecimalBinaryHexadecimalWhere it appears
151111FOne hex digit, four bits
161000010One byte per hex pair begins
64100000040ASCII @, the mark before A
12711111117FHighest 7-bit ASCII code
1281000000080Sign bit of a signed byte
25511111111FFLargest unsigned byte
256100000000100One more than a byte holds
102410000000000400One kibibyte
4095111111111111FFFLargest 12-bit value
655351111111111111111FFFFLargest unsigned 16-bit value

Converting by hand

To go from any base to decimal, multiply each digit by the base raised to its position, counting from zero on the right, and add them. Hex 2F is 2 × 16 + 15 = 47. Binary 1011 is 8 + 0 + 2 + 1 = 11.

To go from decimal to any base, divide repeatedly by the base and read the remainders bottom to top. 47 ÷ 16 is 2 remainder 15, and 2 ÷ 16 is 0 remainder 2, so the digits are 2 and 15, which is 2F.

Binary to hex without arithmetic

Group the binary digits into fours from the right, padding the leftmost group with zeros, and replace each group with its hex digit. 110101111 becomes 0001 1010 1111, which is 1AF. The reverse works the same way: expand each hex digit into four bits.

Octal groups by three instead. That is why a Unix permission of 755 reads as 111 101 101: read, write and execute for the owner, read and execute for everyone else. Each octal digit is exactly one three-bit permission set.

Prefixes and how to read them

Most languages mark the base with a prefix: 0b for binary, 0o or a leading 0 for octal, 0x for hexadecimal. A bare number is decimal. The leading-zero octal convention in C is a well-known source of bugs, since 010 is eight, not ten.

Hexadecimal is case-insensitive: FF and ff are the same value. CSS colours use the same notation, so #FF8000 is three bytes, 255 red, 128 green and 0 blue, which is why hex colour codes are six characters long.

Frequently Asked Questions

What is 255 in binary?

255 in decimal is 11111111 in binary, which is eight ones, the largest value a byte holds.

What is FF in decimal?

Hexadecimal FF is 255 in decimal: 15 × 16 + 15.

Why do computers use hexadecimal?

Sixteen is two to the fourth, so one hex digit is exactly four binary digits. It is a compact, exact shorthand for binary.

How do I convert binary to hex?

Group the bits in fours from the right and replace each group with its hex digit. 1010 1111 is AF.

What base is 0x used for?

0x marks a hexadecimal number, base 16. 0b marks binary and 0o marks octal.