Binary Converter
Write a whole number in binary, octal, decimal or hexadecimal and read it back in all four — exactly, at any size.
Inputs
Result
Converted values
Formula
- value = Σ digit × base^position
- 1 hex digit = 4 bits
- 1 octal digit = 3 bits
Any whole number can be written in any base. The digits are weighted by powers of that base, counting from the right: 1010 in binary is 1×2^3 + 0×2^2 + 1×2^1 + 0×2^0 = 10 in decimal. Hexadecimal is shorthand for binary because one hex digit is exactly four bits (a nibble) and one octal digit exactly three, so long bit patterns stay short without changing the value — FF is four bits plus four bits, 1111 1111.
This converter handles whole, non-negative integers only. There is no fractional part, and no signed or two's-complement interpretation yet — that will be its own digital-systems tool. Write the digits straight through: no spaces, commas or other separators, though an optional matching prefix (0b, 0o, 0x) is accepted, and hex letters may be upper or lower case.
Values are converted with BigInt, never a floating-point number, so a value past 2^53 converts exactly: 2^64 - 1 still comes out as its full 18446744073709551615 in decimal and all 64 of its bits in binary.
About this calculation
Binary, octal and hexadecimal are different bases for writing the same whole number, and digital work constantly moves between them: hex because four bits map to exactly one hex digit, octal because three bits map to one, and decimal because that is how the numbers are read. The converter shows a value in all four bases at once and works in exact integer arithmetic, so values beyond the 2⁵³ limit of a JavaScript number stay exact rather than being rounded.
Assumptions and limits
- It converts whole numbers. Fractions, and the IEEE 754 representations used by floating-point hardware, are a different problem.
- Negative values are not converted into two's complement: a minus sign is kept as a sign, which is how a calculator normally shows them.
- Digits are grouped for readability, but the grouping is presentation — 1 0110 is not a different number from 10110.
A worked example
The binary value 1011 is 11 in decimal, 13 in octal and B in hexadecimal, because 8 + 0 + 2 + 1 = 11, and hex is used in digital work because four bits map to exactly one hex digit.
See also ADC Resolution and Nyquist Sampling.