DevToolsmith

Number Base Converter

Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36. Handles 0x, 0b and 0o prefixes, negative numbers and integers of any size, and shows two’s complement bits for 8, 16, 32 and 64-bit types.

Runs 100% in your browser — nothing is uploaded

Input base

Read as base 16 from the prefix.

Decimal
255
Hexadecimal
ff
Binary
1111 1111
Octal
377
Base 36
73

Fixed-width integer (two’s complement)

Bits
00000000 00000000 00000000 11111111
Hex
0x0000_00ff
As signed int32
255
As unsigned uint32
255

Binary, octal, decimal and hex

DecimalHexBinaryOctal
0 0 0 0
1 1 1 1
2 2 10 2
7 7 111 7
8 8 1000 10
9 9 1001 11
10 A 1010 12
15 F 1111 17
16 10 1 0000 20
31 1F 1 1111 37
32 20 10 0000 40
64 40 100 0000 100
100 64 110 0100 144
127 7F 111 1111 177
128 80 1000 0000 200
255 FF 1111 1111 377
256 100 1 0000 0000 400
1024 400 100 0000 0000 2000
65535 FFFF 1111 1111 1111 1111 177777

One hex digit is exactly four bits, which is why hex is used for bytes (FF = 1111 1111), colors (#1E90FF), memory addresses and hashes. One octal digit is three bits.

Number literals in code

LanguageHexBinaryOctal
JavaScript, Python, Rust, Swift0xff0b10100o755
Go0xff0b10100o755 or 0755
C, C++, Java0xff0b1010 (C23, C++14, Java 7)0755
C#0xff0b1010none

Most of these also allow digit separators: 1_000_000 in JavaScript, Python, Java, Go and Rust, 1'000'000 in C++. The converter accepts underscores, spaces and commas in its input.

Converting in code

JavaScript
(255).toString(16);          // 'ff'
(255).toString(2);           // '11111111'
parseInt('ff', 16);          // 255
parseInt('11111111', 2);     // 255

// Above 2^53, use BigInt
BigInt('0xffffffffffffffff').toString(10); // '18446744073709551615'
Python
hex(255), bin(255), oct(255)   # ('0xff', '0b11111111', '0o377')
int("ff", 16), int("0b1010", 0) # (255, 10)  base 0 reads the prefix
format(255, "08b")              # '11111111'
Shell
printf '%x\n' 255        # ff
echo $((16#ff))           # 255
echo "obase=2; 255" | bc  # 11111111

Converting file permissions? The chmod calculator explains octal modes like 755 bit by bit.

Frequently asked questions

How do I convert decimal to binary?

Type the decimal number into the converter above; the binary, hex, octal and base-36 values appear instantly. By hand, divide by 2 repeatedly and write down the remainders from last to first: 13 → 6 r1 → 3 r0 → 1 r1 → 0 r1, so 13 is 1101.

How do I convert hex to decimal?

Paste the hex value, with or without 0x, and choose Hex (or leave Auto with the 0x prefix). Manually, multiply each digit by a power of 16 from the right: 0x2F = 2 × 16 + 15 = 47. A–F stand for 10–15.

What is two’s complement?

It is how computers store negative integers. In an 8-bit signed integer, -1 is stored as 11111111 (0xFF), the same bits as unsigned 255. To negate a number, invert all bits and add 1. The fixed-width panel shows the bits for 8, 16, 32 and 64 bits and how the same bits read as signed and unsigned.

Is there a size limit?

No. The converter uses JavaScript BigInt, so numbers with hundreds of digits convert exactly. Many online converters use normal JavaScript numbers and silently lose precision above 9,007,199,254,740,991 (2^53 − 1), which breaks 64-bit values such as IDs and hashes.

Where are octal numbers still used?

Mainly for Unix file permissions: chmod 755 is octal, where each digit is three permission bits (rwx). See the chmod calculator for details. Some languages also write octal literals with a leading 0 or 0o, which is why 010 can mean 8 in older C and JavaScript code.