oktools

Number Base Converter

Convert between binary, octal, decimal and hexadecimal — or any base from 2 to 36 — in every field at once, so hex to decimal, decimal to binary and binary to hex are one conversion read from different fields. Values are held as BigIntegers, so a 256-bit hash converts digit for digit instead of being rounded off. Nothing leaves your browser.

Value in every base

base
Start from:

Bit view

8Bits
1Bytes
uint8Smallest type
Click any bit to flip it — every field follows.
7FF0

How it works

Every field on the page is a view of one value, and that value is a BigInt rather than a JavaScript number. Whichever field is typed into is read digit by digit, the running total multiplied by the base and the digit added, and the other four are rewritten from the result, so hex to decimal and decimal to binary are one conversion seen from different fields. A JavaScript number has 53 bits of precision, so parseInt turns FFFFFFFFFFFFFFFF into 18446744073709552000; a BigInt has no such ceiling, and this page returns 18446744073709551615, the number those sixteen digits name.

Each field filters as you type instead of complaining afterwards: a character its base cannot hold is dropped on the way in and named below the fields, so the binary field can only ever show a binary number. Spaces, underscores and commas are kept, because pasted numbers arrive with them, and so is a leading sign. A 0x, 0b or 0o prefix at the front switches the digits after it to the base it names, with a note saying so, but only where the field’s own digits cannot spell its letter: 0BE in the hex field is three digits, 190.

Below the fields the value is shown as the bit pattern it has in memory. At a fixed width of 8, 16, 32, 64 or 128 bits that pattern is the two’s complement, the value reduced modulo two to the power of the width, so −4 at 8 bits is 1111 1100, or 0xFC. Clicking a bit flips it, Shift left, Shift right and Invert work on the pattern at the width on screen, and a right shift of a negative value copies the sign bit down. The fixed-width table says whether the value fits each uint and int type.

Examples

Convert a 64-bit value to hex and binary

A converter built on floating point rounds this decimal to 18446744073709552000, a different number; here every field agrees exactly and the smallest type reads uint64.

Decimal
18446744073709551615
Other fields
Hexadecimal    FFFF FFFF FFFF FFFF
Binary         1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
Smallest type  uint64

Read a chmod value as bits

Each octal digit is three bits, which is why Unix permissions are written in octal: 7 5 5 is 111 101 101 for owner, group and others. The binary field regroups the same bits in fours.

Octal
755
Other fields
Binary          1 1110 1101
Decimal         493
Hexadecimal     1ED
16-bit pattern  0x01ED

See a negative number as two’s complement

The fields keep the sign, because no base’s digits can carry it; the bit view and the width table show the pattern a register holds. Shift right from here and every field reads −2.

Decimal
-4
Bit view and fixed widths
Hexadecimal    -4
Smallest type  int8
8-bit grid     1111 1100 (FC)
16-bit         0xFFFC
32-bit         0xFFFFFFFC
64-bit         0xFFFFFFFFFFFFFFFC

Paste a prefixed literal into the wrong field

The decimal field cannot spell X as a digit, so the prefix is honoured, the value is read as hex and the other fields fill in. The hexadecimal field reads the same literal the same way.

Typed into the Decimal field
0xDEADBEEF
Result
Read as hexadecimal — its prefix says so
Binary       1101 1110 1010 1101 1011 1110 1110 1111
Octal        33 653 337 357
Decimal      3 735 928 559
Hexadecimal  DEAD BEEF

Supported formats

  • Binary, octal, decimal, hexadecimal and a custom baseFour fixed fields plus one in any base from 2 to 36, digits 0–9 then a–z; base 36 reads short identifiers (1295 is ZZ). Letters are accepted in either case.
  • Prefixed literals0x, 0b and 0o, as in C, Python and JavaScript, accepted at the front after an optional sign in any field whose digits cannot spell the letter. Nothing is a prefix anywhere but the front: 10x5 is 105.
  • Separators, signs and lengthSpaces, underscores and thousands commas are kept while typing and ignored when reading, so 1_000_000, 1,024 and 1111 0000 all read. A leading + or − is kept through every base. Up to 4096 characters.
  • Grouped and plain outputGroup digits spaces binary and hex in fours and octal and decimal in threes, from the right. Copy buttons copy the plain value; Copy all writes Decimal: 255, Hex: 0xFF, Octal: 0o377 and Binary: 0b11111111 on four lines.
  • Sizes and widthsBits and bytes for the magnitude, the smallest C type that holds the value (uint8 to uint128, or int8 to int128 when negative), a table of which widths fit, and arrow keys that step the value by one.

Use cases

  • Check whether a value fits an integer typeType a count or an identifier and read the table: uint32 holds up to 4 294 967 295 and int32 up to 2 147 483 647, so “does not fit” is the overflow before it happens.
  • Decode a flags or permissions maskPaste the mask — 0x1F, 0o755, a decimal from a database column — and read which bits are set in the grid. Flip one and the hex for the code is in the field above.
  • Convert database and API identifiers exactlySnowflake IDs, 64-bit hashes and 256-bit digests all exceed 53 bits, so a spreadsheet or a float-based converter alters their last digits. Here they convert digit for digit, in either direction.
  • Make sense of a hex dumpFFFFFFFC in the hexadecimal field is 4 294 967 292 and fits uint32 but not int32; type −4 and the 32-bit row shows the same pattern, which is how the two readings are told apart.

Limitations

  • Whole numbers onlyA decimal point is refused, and there is no floating-point view. To see how 3.5 is stored as a float, get the integer from Python’s struct or Java’s Float.floatToIntBits and paste that here.
  • Hex is always read as unsignedThere is no “treat as signed” switch: FFFFFFFF in the hexadecimal field is 4 294 967 295, never −1. The two’s complement reading lives in the bit view and the width table.
  • No arithmetic between two valuesThe page steps, shifts, inverts and flips bits on one value; it does not add, multiply, AND or OR two. A programmer’s calculator or a console with BigInt literals does that.
  • The bit view stops at 128 bitsA wider value still converts exactly, but the grid, the shifts and the width table have nothing to show for it, and the page says so.
  • Bytes are shown most significant firstThe grid reads from the top bit, as a hex literal is written. A little-endian memory dump stores the bytes the other way round, so reverse them before pasting.

Frequently asked questions

How do I convert binary to decimal?

Type or paste the binary digits into the Binary field. The decimal, octal and hexadecimal fields fill in as you type, so one conversion gives you all of them at once. It works the other way round too — every field is an input.

How do I convert decimal to hex?

Enter the number in the Decimal field and read the result from the Hexadecimal field. Use the copy button beside it to put the value on your clipboard, with or without digit grouping and in upper or lower case.

Can it convert numbers bigger than 64 bits?

Yes. Every value is held as a BigInt, so a 256-bit hash or a 2048-bit key converts digit for digit with no rounding. JavaScript numbers lose precision above 2^53, which is why parseInt-based converters quietly return the wrong decimal for long hex strings.

What do the 0x, 0b and 0o prefixes mean?

0x marks a hexadecimal literal, 0b a binary one and 0o an octal one, the same as in C, Python, Rust and JavaScript. You can paste a prefixed value into any field whose base cannot spell the prefix letter as a digit: the decimal, binary and octal fields read 0xFF as hex and show it in all the others. The hexadecimal field reads 0B as two of its own digits, so 0b1010 typed there is the hex number 0B1010, not binary ten.

Why will a field not accept some of the characters I type?

Each field only holds digits its own base is written in, so the binary field takes 0 and 1, the octal field 0 to 7, and the hexadecimal field 0-9 and A-F. Anything else is turned away as it is typed and the field says which character it refused, which means a value on screen is always a real number in that base. Spaces, underscores and commas are kept so a number pasted with separators still reads, and a 0x, 0b or 0o prefix switches the digits after it to the base the prefix names, wherever the field’s own digits do not already include that letter.

How are negative numbers handled?

A leading minus sign is kept through every base, so −255 shows as −FF in hex. The bit view and the width table show the two’s complement pattern that the value has in memory at 8, 16, 32, 64 and 128 bits, which is what a debugger or a hex dump would display. Shifting such a value right keeps its sign, as it does for a signed integer.

Are the numbers I convert sent anywhere?

No. The conversion runs entirely in your browser with no network request of any kind, so values you paste here never reach a server, a log file or an analytics event.