Skip to content
Binary Converter

Binary, octal, decimal and hex — four fields, all live, and two’s complement done properly

Type into any one of the four fields and the other three follow. Everything is parsed and printed through BigInt, so a full 64-bit value survives: 0xFFFFFFFFFFFFFFFF is 18,446,744,073,709,551,615 here and not the rounded-off number a converter built on ordinary JavaScript numbers hands back. Negative values get their own labelled two’s complement mode with a bit-width selector, because “−5 in binary” has no answer until you say how many bits. Nothing is uploaded or saved.

  • Nothing is uploaded or saved
  • Works offline
Negatives
ValuesArbitrary width · BigInt
Binarybase 2
Octalbase 8
Decimalbase 10
Hexbase 16
Bits needed
8
Fits in
8-bit
Hex digits
2
Sign
Positive
Bits8 bits, most significant first

Bit 7 is on the left and bit 0 on the right, which is how a value is written. Each bit is worth twice the one to its right.

How it works

  1. 1

    Type in whichever base you have

    Binary, octal, decimal and hex are four equal fields, and the one you are editing is the source — the other three are rewritten from it on every keystroke. Prefixes are accepted, so 0xFF pasted out of source code works as well as FF, and spaces, underscores and commas are ignored wherever they fall.

  2. 2

    Turn grouping on to read long values

    Grouping splits binary into nibbles of four, hex into pairs, octal into threes and decimal into thousands. Nibbles matter because one hex digit is exactly four bits, so grouped binary lines up digit for digit with the hex above it: 1111 1011 is FB. Pairs matter because two hex digits are exactly one byte, which is how memory dumps are printed.

  3. 3

    Check the width badge before you pick a type

    The badge says how many bits the value actually needs and which of the standard widths it fits in. 255 needs 8 bits and fits a byte; 256 needs 9 and does not. This is the question behind most integer bugs, and it is easier to answer by looking than by remembering where the boundaries fall.

  4. 4

    Switch to two’s complement for negative values

    Pick a width — 8, 16, 32 or 64 — and the decimal field takes a signed value while the other three show the raw bit pattern for that width, zero-padded so it can be read as fixed-width. −5 in 8 bits is 11111011, or FB, which read as unsigned is 251. Flip the width to 16 and the same −5 becomes 1111111111111011. That change is the whole reason the mode exists as a separate labelled mode instead of a checkbox.

  5. 5

    Toggle individual bits

    Where the value fits, the bits are drawn as a row you can click. Set bit 7 of an empty byte and the decimal reads 128; set bits 0 and 1 as well and it reads 131. It is the fastest way to build or read a flags field, and in two’s complement mode setting the top bit is what makes the value go negative, which the decimal field shows immediately.

Frequently asked questions

What is −5 in binary?

The honest answer is that the question is incomplete. In two’s complement — the representation essentially every processor and language uses for signed integers — the answer depends entirely on the width: −5 is 11111011 in 8 bits, 1111111111111011 in 16 bits, and thirty-two or sixty-four digits long in the wider forms, all of them equally correct. That is why this page puts negatives in their own mode with a width selector instead of printing one answer. If all you want is a magnitude with a sign in front, the default mode gives you −101, which is fine for arithmetic on paper and is not what any machine stores.

Why do other converters get large hex values wrong?

Because they run on ordinary JavaScript numbers, which are doubles and hold integers exactly only up to 2⁵³ — 9,007,199,254,740,992. Above that, values are rounded to the nearest representable one, silently and with no error. 0xFFFFFFFFFFFFFFFF should be 18,446,744,073,709,551,615; through parseInt it comes back as 18,446,744,073,709,552,000, which is wrong in the last four digits. This page parses and prints through BigInt, which has no such limit. Type 9007199254740993 into the decimal field and it survives the round trip in every base.

How is two’s complement different from just using a sign bit?

A sign bit means reserving the top bit for the sign and reading the rest as a magnitude, which gives you two zeros — a positive and a negative one — and needs the hardware to branch on the sign for every addition. Two’s complement instead represents a negative value as the pattern that, added to its positive counterpart, wraps to zero for the given width: 5 is 00000101, −5 is 11111011, and the two add to 100000000, which is nine bits and so keeps only the low eight. Ordinary unsigned addition therefore just works, and there is exactly one zero. The cost is asymmetry: 8 bits reach −128 but only +127, which is why an 8-bit −128 has no positive twin.

How many bits does my number need?

The number of binary digits it has, once leading zeros are dropped — which is what the badge above reports. 255 is 11111111, so 8 bits; 256 is 100000000, so 9. The pattern worth memorising is that each extra bit doubles the range: 8 bits reach 255 unsigned, 16 reach 65,535, 32 reach 4,294,967,295 and 64 reach 18,446,744,073,709,551,615. In two’s complement half the range goes to negatives, so a signed 32-bit value stops at 2,147,483,647, which is 0x7FFFFFFF and the number behind a long list of overflow bugs.

Why is hex used everywhere instead of binary?

Because 16 is 2⁴, so one hex digit is exactly four binary digits with no remainder and no arithmetic needed to convert. FB is 1111 1011, digit for digit, which is why a memory dump printed in hex can be read as bits by anyone who knows the sixteen four-bit patterns. Two hex digits are exactly one byte, so a colour like #FF8800 is three bytes and an address like 0x7FFF is unambiguous about its width. Binary is unreadable at length and decimal hides the byte boundaries; hex does neither.

What is octal still for?

Mostly Unix file permissions, and it is a good fit there for the same reason hex fits bytes: 8 is 2³, so one octal digit is exactly three bits, and permissions come in groups of three — read, write, execute. That is why chmod 755 is a natural way to write rwxr-xr-x, and why it reads as 111 101 101 in binary. Outside that, octal is largely historical. It is included here because permission values are the one place people still meet it and are least sure of the conversion.

Do the 0x, 0b and 0o prefixes matter?

To a human, yes — the prefix is what says which base a written value is in, and 11 means eleven, three or seventeen depending on it. To this page they are optional: each field already knows its own base, so a prefix is accepted and stripped if it matches that field. The output is printed without one so it can be pasted anywhere, and hex letters are printed in uppercase with the prefix left off, which is the form that reads most clearly in a table.

Can it convert fractions, like 0.1 in binary?

No — this tool converts integers only, and refuses a decimal point rather than pretending. Fractional binary is a genuinely different problem: 0.1 has no finite binary expansion, which is exactly why 0.1 + 0.2 does not equal 0.3 in most languages, and a floating-point value is a sign, an exponent and a mantissa packed into 32 or 64 bits rather than a straightforward positional expansion. Showing one as a plain binary string would be misleading about what is stored.

Does anything I type here leave my browser?

No. The parsing and formatting are a small amount of JavaScript this page already loaded, there is no request of any kind at any point, and the page works with the network disconnected. Nothing is written to localStorage either — which is the right default for a tool people paste hashes, keys and flag values into.