gazza.ltd

Number Base Converter

Binary
0b11111111
Octal
0o377
Decimal
255
Hexadecimal
0xFF
Bits needed
8

Prefixes like 0x, 0b and 0o are accepted and stripped automatically. Digits that do not exist in the chosen base are rejected rather than silently ignored — pasting 1092 as binary tells you so, instead of quietly reading it as 1.

Ad

Convert a number between binary, octal, decimal and hexadecimal, seeing all four at once. Prefixes like 0x are handled automatically, and digits that are invalid for the base you picked are flagged rather than quietly ignored.

How it works

A base is simply how many distinct digits are available before you need another column. Decimal has ten, binary two, octal eight, hexadecimal sixteen. The underlying quantity never changes — only how it is written.

Conversion works by reading the input into a single numeric value using the source base, then writing that value out in each target base. Before that, every character is checked against the source base, so a stray 9 in an octal number produces an error instead of a plausible but wrong answer.

Binary and hexadecimal line up neatly: each hex digit is exactly four bits. That relationship is why hex is used for colours, memory addresses and byte dumps — it is binary, four times shorter.

Worked example

Decimal 255 is 11111111 in binary, 377 in octal and FF in hex. The binary form is eight ones, which is exactly one byte with every bit set — which is why 255 turns up everywhere in computing, from colour channels to network masks.

That connection is visible in web colours: #FFFFFF is white because each of the three channels is set to its maximum of 255. ConvertFF from hex and the reason becomes obvious.

Common questions

Why does hexadecimal use letters?

Base 16 needs sixteen digits and we only have ten, so A to F stand in for the values ten to fifteen. Hex is popular because one hex digit maps exactly to four bits, making it a compact way to write binary.

What are the 0x and 0b prefixes?

Conventions from programming languages marking which base a literal is written in — 0x for hex, 0b for binary, 0o for octal. They are not part of the number. This tool strips them automatically so you can paste code straight in.

Why does it reject some digits?

Because they do not exist in the base you chose. There is no digit 2 in binary, and no F in decimal. Many converters silently stop reading at the first invalid character and return a wrong answer, which is worse than an error.

Where is octal still used?

Mostly Unix file permissions. A mode of 755 is octal, and each digit is three bits representing read, write and execute. That is why permissions are conventionally written as three digits rather than in decimal.

What does "bits needed" tell me?

How many binary digits the value requires, which indicates the smallest integer type that can hold it. Anything needing more than 32 bits will not fit in a standard 32-bit integer, which is worth knowing before storing it.

Is there a maximum?

JavaScript handles integers exactly up to about 9 quadrillion — 2 to the power of 53. Beyond that, precision is lost and the result cannot be trusted, so very large values need specialist arbitrary-precision tools.

Related tools