Programming tool

Number Base Converter

Convert integers between binary, octal, decimal, and hexadecimal in one place, with exact results for negative and very large values.

Integers only. A leading minus sign is supported.

Equivalent values

Binary0b
—
Octal0o
—
Decimalbase 10
—
Hexadecimal0x
—

What are number bases?

A number base tells you how many unique digits are used before a new place value begins. This converter works with whole integers in binary, octal, decimal, and hexadecimal.

Binary: 0 and 1 | Octal: 0-7 | Decimal: 0-9 | Hexadecimal: 0-9 and A-F

Binary, octal, decimal, and hexadecimal

Binary is base 2 and is the language of digital circuits. Octal is base 8 and can compactly represent groups of three binary digits. Decimal is base 10, the everyday counting system. Hexadecimal is base 16; its digits A through F represent values 10 through 15.

Programmers use hexadecimal because one hex digit maps neatly to four binary bits. That makes long binary values easier to read, while keeping their exact bit pattern visible. Prefixes such as 0b, 0o, and 0x commonly identify binary, octal, and hexadecimal values in code.

How base conversion works

To convert a positive integer from another base to decimal, multiply each digit by its base raised to that digit's position, starting at zero on the right. To convert decimal to another base, repeatedly divide by the target base and read the remainders from bottom to top. Negative values keep the minus sign while their magnitude is converted.

1010₂ = 1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 10₁₀
255₁₀ = 11111111₂ = 377₈ = FF₁₆

Binary place values

From right to left, binary places represent powers of two: 1, 2, 4, 8, 16, 32, and so on. For example, 1010 has a 1 in the eight's place and a 1 in the two's place, so its decimal value is 8 + 2 = 10.

Frequently asked questions

Does this converter support negative numbers?

Yes. Enter a minus sign before the digits, such as -42. The sign is retained in every representation.

Can I convert very large integers?

Yes. The converter uses exact BigInt arithmetic instead of JavaScript Number, so values larger than Number.MAX_SAFE_INTEGER remain accurate.

Why is my input rejected?

Each base permits a specific digit range. Binary allows 0-1, octal 0-7, decimal 0-9, and hexadecimal 0-9 plus A-F. This tool does not accept fractions or decimal points.

How the number base converter works

Pick the base your number is written in, type the digits, and the converter shows the same value in binary, octal, decimal, and hexadecimal at once. Each result has a copy button and is labeled with the prefix programmers normally use: 0b for binary, 0o for octal, and 0x for hexadecimal. Enter the digits only, without a prefix, and the tool validates them against the digit set of the selected base before converting.

The conversion uses JavaScript BigInt arithmetic rather than floating-point numbers, so there is no upper limit on the size of the integer and no rounding. A leading minus sign is accepted and kept on every output. Fractions, decimal points, spaces, and underscores are not accepted; the tool works with whole integers only.

How positional number systems work

Every base uses the same idea: each digit position is worth the base raised to a power, counting from zero at the rightmost digit. In decimal the positions are worth 1, 10, 100, and so on. In binary they are worth 1, 2, 4, 8, 16. In hexadecimal they are worth 1, 16, 256, 4096. To read a number in any base, multiply each digit by its place value and add the results.

value = d₃ × b³ + d₂ × b² + d₁ × b¹ + d₀ × b⁰
1010₂ = 1 × 8 + 0 × 4 + 1 × 2 + 0 × 1 = 10₁₀
255 = 0xFF = 0b11111111 = 0o377

Going the other way, from decimal to another base, you divide repeatedly by the target base and collect the remainders. For 255 into hexadecimal: 255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15. Reading the remainders from last to first gives F F, so 255 is 0xFF. The same process with base 2 produces eight ones, 11111111, and with base 8 produces 377.

Why programmers use binary, octal, and hexadecimal

Computers store everything as bits, and binary shows those bits directly. It is verbose, though: a 32-bit value needs 32 binary digits. Hexadecimal solves that because 16 is 2 to the fourth power, so one hex digit stands for exactly four bits and a byte is always two hex digits. That is why memory addresses, color codes such as #FF8800, hashes, MAC addresses, and raw byte dumps are written in hex.

Octal groups bits in threes, since 8 is 2 to the third power. It is less common today but still appears in Unix file permissions, where 0o755 means the owner has read, write, and execute (binary 111) while group and others have read and execute (binary 101).

  • Binary (base 2) – digits 0–1, prefix 0b, one digit per bit
  • Octal (base 8) – digits 0–7, prefix 0o, one digit per three bits
  • Decimal (base 10) – digits 0–9, no prefix, everyday arithmetic
  • Hexadecimal (base 16) – digits 0–9 and A–F, prefix 0x, one digit per four bits

Negative numbers and two's complement

This converter treats a negative number as a sign plus a magnitude, so -10 in decimal is shown as -1010 in binary and -A in hexadecimal. That is the mathematically correct representation, but it is not how CPUs store negative integers. Hardware uses two's complement with a fixed width: to represent -x in n bits, it stores 2ⁿ − x. In 8 bits, -1 becomes 255 (0xFF) and -10 becomes 246 (0xF6).

If you need the two's complement form, decide on the bit width first, add 2ⁿ to the negative value, and convert the resulting positive number. For -10 in 8 bits, 256 − 10 = 246, which this tool converts to 0xF6 or 0b11110110.

Large integers and precision

JavaScript's regular Number type can only represent integers exactly up to 2⁵³ − 1, which is 9,007,199,254,740,991. Many online converters silently lose digits beyond that point, which matters for 64-bit database IDs, Snowflake IDs, cryptographic values, and hashes. This tool parses and formats with BigInt, so a 64-bit or 256-bit value converts digit for digit.

Hexadecimal input is case-insensitive and output is shown in uppercase. Leading zeros are accepted on input and dropped on output, so 0b00001010 and 1010 both convert to 10.

Frequently asked questions

How do I convert binary to decimal by hand?

Write the place values 1, 2, 4, 8, 16, and so on under the binary digits from right to left, then add up the place values that sit under a 1. For 1101 that is 8 + 4 + 1 = 13.

How do I convert decimal to hexadecimal?

Divide the number by 16 and note the remainder, then divide the quotient by 16 again until it reaches zero. Read the remainders from last to first, writing 10 through 15 as A through F. For 4,000: 4000 ÷ 16 = 250 r0, 250 ÷ 16 = 15 r10, 15 ÷ 16 = 0 r15, so 4,000 is 0xFA0.

What is 255 in binary, octal, and hexadecimal?

255 is 11111111 in binary, 377 in octal, and FF in hexadecimal. It is the largest value that fits in one unsigned byte.

Does the converter handle negative numbers?

Yes. Type a minus sign before the digits and it is kept on every output, for example -42 becomes -101010 in binary. The tool does not produce two's complement bit patterns; add 2ⁿ for your bit width first if you need those.

Can I convert fractions or decimal points?

No. The converter accepts whole integers only. Values such as 3.14 or 0.5 are rejected because fractional conversion between bases requires a separate algorithm and usually does not terminate exactly.

What is the largest number the converter supports?

There is no fixed limit. The tool uses BigInt arithmetic, so values far beyond JavaScript's 2⁵³ − 1 safe-integer limit, including 64-bit and 128-bit values, convert exactly.