Converters

Number Base Converter

Convert a number between binary, octal, decimal, and hexadecimal. Runs entirely in your browser.

Binary

11111111

Octal

377

Decimal

255

Hexadecimal

FF

Advertisement

How it works

Type a number, choose the base it is written in, and the binary, octal, decimal and hexadecimal forms appear together. Hexadecimal letters can be upper or lower case; results are shown in upper case without prefixes such as 0x.

Example

255 in decimal is 11111111 in binary, 377 in octal and FF in hexadecimal. Going the other way, choose Hexadecimal and enter 1A to get 26 in decimal.

Size and prefixes

Values are held as exact whole numbers with no upper limit, so a 64-bit ID converts without losing digits. A 0b, 0o or 0x prefix is accepted only when it matches the selected base, so 0b1010 works as binary and 0xFF as hexadecimal, and a prefix for a different base gives an error.

More examples

Octal 755, a common file permission, is 111101101 in binary, 493 in decimal and 1ED in hexadecimal. Decimal 192, the first part of many local network addresses, is 11000000 in binary. A hexadecimal colour such as FF8000 is converted one pair at a time: FF is 255, 80 is 128 and 00 is 0, giving the red, green and blue values 255, 128 and 0.

Spaces, errors and padding

All spaces are removed, so 1111 1111 is read as 11111111, which is 255. Every character must be a valid digit for the chosen base. 12.7, 1012 in binary and 12ab in decimal show an error that names the first bad character instead of being read partway. In hexadecimal mode the letter b is a digit, so 0b1010 there is the hex number 0B1010, not a binary prefix. Results never include padding, so 5 is shown as 101, not 00000101.

Where these bases are used

Binary is how a computer stores values, and each hexadecimal digit stands for exactly four binary digits, which is why FF is 11111111. Octal appears in Unix permissions. Decimal is what people read. Fixed-width forms, such as 8-bit or 32-bit signed values, need padding and two's complement that this tool does not show.

Frequently asked questions

Does this handle negative numbers?

Yes: the minus sign is kept and the digits are converted, so -255 shows as -11111111. It doesn't show two's complement, so it can't show how a negative number is stored in 8, 16 or 32 bits.

What happens if I type a digit that isn't valid for the base?

The tool shows an error naming the first invalid character, for example 2 in a binary number or the decimal point in 12.7. Nothing is read partially, and fractions aren't supported.

Can I paste binary with spaces or a 0b prefix?

Yes. All spaces are removed, so 1111 1111 is read as 255, and a 0b prefix is accepted when Binary is selected (0o for octal, 0x for hexadecimal). A prefix that belongs to a different base is rejected.

Does it pad binary results to 8 or 32 bits?

No. Results are shown without leading zeros, so 5 is 101. Add zeros by hand if you need a fixed width.

Related tools