CalcDuck

Binary Calculator

Binary Calculator

Convert
Decimal
42
Binary
101010
Octal
52
Hexadecimal
2A

Binary, octal, and hexadecimal are positional number systems using base 2, base 8, and base 16 instead of base 10. Decimal 42 is 101010 in binary, 52 in octal, and 2A in hexadecimal, and any whole number can be converted between all four bases the same way computers do internally.

Tip: “Copy with settings” shares a link that opens this calculator with your numbers already filled in.

How this calculator works

Computers store every number in binary (base 2), using only the digits 0 and 1. Octal (base 8) and hexadecimal (base 16) are shorthand notations programmers use because they map cleanly onto groups of binary digits — one hex digit represents exactly 4 bits, and one octal digit represents exactly 3 bits.

This calculator converts a whole number between decimal, binary, octal, and hexadecimal, showing all four representations of the same value side by side. It only handles non-negative whole numbers — negative numbers in binary require a fixed bit width and a two's-complement convention that this calculator does not assume.

How the conversion works

To convert decimal to another base: repeatedly divide by the base and read the remainders in reverse order.To convert another base to decimal: multiply each digit by the base raised to its position, and sum the results.

This calculator only produces exact results for integers up to 2^53 − 1 (9,007,199,254,740,991), the largest integer JavaScript can represent without rounding error. Larger inputs are flagged rather than silently rounded.

Worked example: converting decimal 42

  1. 42 ÷ 2 = 21 remainder 0; 21 ÷ 2 = 10 remainder 1; 10 ÷ 2 = 5 remainder 0; 5 ÷ 2 = 2 remainder 1; 2 ÷ 2 = 1 remainder 0; 1 ÷ 2 = 0 remainder 1.
  2. Reading the remainders bottom to top gives binary 101010.
  3. Grouping those bits in fours (0010 1010) maps directly to hex: 0010 = 2, 1010 = A, so hex is 2A.
  4. Grouping in threes (101 010) maps to octal: 101 = 5, 010 = 2, so octal is 52.

Frequently asked questions

Why do computers use binary instead of decimal?

Binary maps directly onto a transistor's two stable states, on and off, which makes it the natural number system for digital electronics. Decimal would require components with ten distinct, reliably distinguishable states, which is far harder to build cheaply and reliably.

Why do programmers use hexadecimal so often?

One hexadecimal digit represents exactly 4 binary bits (a nibble), so a byte is always exactly 2 hex digits. This makes hex a compact, easy-to-read shorthand for binary data such as memory addresses, color codes, and byte values, without the visual noise of long strings of 0s and 1s.

Can this calculator handle negative numbers?

No. Representing negative numbers in binary requires choosing a fixed bit width and a convention such as two's complement, and different systems make different choices. This calculator only converts non-negative whole numbers, which is unambiguous across all four bases.

What is the largest number this calculator can convert exactly?

2^53 − 1, or 9,007,199,254,740,991. Beyond that, JavaScript's number type can no longer represent every integer exactly, so this calculator flags the input as too large rather than returning a silently rounded answer.

What counts as a valid input for each base?

Binary accepts only the digits 0 and 1; octal accepts digits 0 through 7; hexadecimal accepts digits 0 through 9 plus the letters A through F (in either case). Any other character is rejected.

Sources

Related calculators