Converting binary or hex to decimal: the prefix decides the base
The converter has no "from" menu. It works out the base from how you write the number in Number to convert:
| You type | Read as |
|---|---|
0b1010 |
binary (BIN) |
0o755 |
octal (OCT) |
0xff |
hexadecimal (HEX) |
255 (no prefix) |
decimal (DEC) |
Prefixes are not case-sensitive, so 0XFF and 0xff give the same result. A bare ff is not read as hex. It shows an error, because without a prefix the tool only accepts decimal digits. That rule means 10 always means ten, never two or sixteen.
- Type or paste one integer into Number to convert. Add
0b,0oor0xif it isn't decimal. - Read the result straight away. The four fields below the input and the result panel update as you type.
- Check the Read as tile to confirm which base the tool used.
- Check the Bits tile to see how many binary digits the value needs.
- To show hex digits as
DEADBEEFinstead ofdeadbeef, tick Uppercase output. - Press Copy result to copy all four lines (
BIN:,OCT:,DEC:,HEX:) at once.
You can also type straight into one of the four fields: Binary, Octal, Decimal or Hexadecimal. In those fields you don't need a prefix. Typing ff in the Hexadecimal field is enough, and the tool writes 0xff back into the main input for you.
Worked conversions
Each block shows the four lines from the result panel. The input and the value in the Bits tile are given above each block.
Hex to decimal for 0xDEADBEEF, a common 32-bit marker value. Bits: 32.
BIN: 11011110101011011011111011101111
OCT: 33653337357
DEC: 3735928559
HEX: deadbeef
Binary to decimal for 0b1010. Bits: 4.
BIN: 1010
OCT: 12
DEC: 10
HEX: a
Octal Unix permissions to binary for 0o755. The binary line shows the rwx bits for owner, group and others. Bits: 9.
BIN: 111101101
OCT: 755
DEC: 493
HEX: 1ed
Decimal to hex for 18446744073709551615, the maximum unsigned 64-bit integer. This is larger than JavaScript's normal number type can hold exactly, and every digit is still correct. Bits: 64.
BIN: 1111111111111111111111111111111111111111111111111111111111111111
OCT: 1777777777777777777777
DEC: 18446744073709551615
HEX: ffffffffffffffff
Where a base converter saves time
- Reading a hex dump or a debugger: paste
0x7fffand get32767without working it out in your head. - Checking bit flags: write a mask as
0b00101100to get44for a config file, or type a decimal setting to see which bits it turns on. - File permissions: convert
0o644to binary (110100100) to see which read and write bits are set for owner, group and others. - Sizing a field: the Bits tile shows whether a non-negative ID or counter fits in an unsigned 8, 16, 32 or 64-bit type. For a signed type, add one bit:
0xffffffffshows Bits: 32, so it fits a uint32 but not an int32. - Hex colour channels:
0xccgives204. For full colours with RGB and HSL, use the Color Converter.
Limits and inputs it rejects
The tool handles whole numbers only, one per conversion. When you type any of the inputs below into Number to convert, an error appears at the top of the Result panel and all four fields stay empty:
- Fractions and scientific notation:
3.5and1e3are rejected. - Digit separators:
1_000,1,000and1 000are rejected. Remove the separators first. - Digits that don't belong to the base:
0b102fails because2is not a binary digit. - A prefix with no digits after it, such as
0x. - Hex letters without a
0xprefix in the main input.
Spaces before or after the number are ignored. A negative number is converted as a minus sign plus its magnitude, so -42 gives -101010 in binary and -2a in hex. The tool does not produce two's complement, so -1 will not come back as ffffffff. If you need the bit pattern a signed 32-bit register would hold, add 2³² to the negative value first: -42 + 4294967296 = 4294967254, which converts to ffffffd6.
There is no fixed bit width such as 8, 16, 32 or 64. Thanks to BigInt, inputs hundreds of digits long stay exact. Only bases 2, 8, 10 and 16 are shown.
If your binary string is encoded text, such as 01001000 01101001, you want to decode characters, not convert one number. Use Binary to text instead.