Smekys
Ad Space

Binary Calculator

Free binary calculator converts whole numbers between decimal (base 10), binary (base 2), hex (base 16) and octal (base 8), with padded bits.

Enter Values

base 10

A non-negative whole number you want converted. Use 0 to 4,294,967,295 (32-bit range).

bits

Pad the binary result with leading zeros to at least this many bits (e.g. 8 = one byte).

bits

Output word width in bits (4, 8, 16 or 32). The padded bit length is the larger of this and the number's actual bit length.

Result

Decimal (base 10)
42
Binary (base 2)
00101010
Octal (base 8)
52
Hexadecimal (base 16)
2A
Bit Length
6
Padded Word Width
8

Computers speak in binary, but people write numbers in decimal. This binary calculator bridges the two: type any whole number in decimal (base 10) and the tool instantly shows its equivalent in binary (base 2), octal (base 8), and hexadecimal (base 16). It also reports the bit length — how many binary digits the value actually needs — and can pad the binary string with leading zeros so it lines up neatly on byte boundaries.

Whether you are a programmer reading a register dump, a student doing computer-science homework, or an engineer debugging a communications protocol, switching between number bases by hand is slow and error-prone. The converter below removes that friction: one input, four representations, updated as you type.

Approximation note. The pure-arithmetic engine cannot emit alphabetic hex digits A–F or pad a bit string with leading zeros as text, so the Hexadecimal and Octal result rows return the decimal value of those digits grouped by place (e.g. 42 shows as 42 rather than 2A; 255 shows as 255 rather than FF). The Binary row is likewise returned as a packed integer rather than a zero-padded string. Use the worked examples below to read the standard letter-coded notation, or verify against your language's toString(2/8/16) in the browser.

How to Use

  1. Enter a whole number in the Decimal Number field. Start with something small, like 42, to see how the digits break apart.
  2. Watch the result card. The Binary (base 2) line shows the pure base-2 digits without a 0b prefix, the Octal (base 8) line drops the 0o prefix, and the Hexadecimal (base 16) line drops the 0x prefix.
  3. Adjust the Pad Binary To field if you want leading zeros. Setting it to 8 formats the result as exactly one byte; setting it to 16 lines it up as two bytes (a 16-bit word). Leave it at 1 to show the bare minimum digits.
  4. Read the Bit Length line to understand how many bits the value occupies. A number from 0 to 255 fits in 8 bits; 256 jumps to 9 bits.
  5. To convert in the opposite direction — say, from hex to decimal — multiply each digit by its power of sixteen, or simply reverse-engineer it: type the equivalent decimal until the hex line matches your target.

The engine computes each place digit arithmetically (remainder mod the base) and sums them as a packed integer, so the numeric values match what Python's bin(), oct(), and hex() would compute — but the alphabetic hex letters and zero-padded string layout are not emitted by the arithmetic engine. Use the grouping worked examples below to read the standard notation.

How Number Bases Work

A number's value does not change when you rewrite it in another base — only the notation does. In decimal, each position is a power of ten. In binary, each position is a power of two. Take 42:

  • Binary: 101010 = 1×32 + 0×16 + 1×8 + 0×4 + 1×2 + 0×1 = 42.

Each binary digit, or bit, contributes a weight that doubles as you move left. From the right edge, the weights are 1, 2, 4, 8, 16, 32, 64, 128. Think of them as fractions of a byte when you work the other way: the first bit to the right of an imaginary point stands for 50%, the next 25%, then 12.5%, 6.25%, and so on — which is why binary is so natural for digital signal levels, where a wire is either on (1) or off (0).

Hexadecimal compresses binary because one hex digit equals exactly four binary digits (16 = 2⁴). A byte of eight bits therefore becomes two hex digits, ranging from 00 to FF. Octal uses groups of three bits (8 = 2³), which is why you sometimes see Unix file permissions written as three octal digits such as 755.

Examples

Example 1 — A classroom value. Enter 42 with padding at 8 bits. Decimal is 42; the binary digit string is 101010 (six significant bits; padded to an 8-bit byte = 00101010); octal digits are 52; the numeric hex field reads 42; bit length is 6. Written in standard hex notation the same value is 2A, and grouping 00101010 as 0010 and 1010 gives hex digits 2 and A.

Example 2 — The full byte. Enter 255. The binary digit string is 11111111 — every bit on; octal digits are 377; the numeric hex field reads 255 (standard hex notation FF); bit length is 8. This is the largest value that fits in a single unsigned byte, which is why the range 0–255 appears so often in colors (RGB channels), character codes, and low-resolution sensors.

Example 3 — Crossing the byte boundary. Enter 256. Binary is 100000000 (nine bits); octal is 400; the numeric hex field reads 256 (standard hex notation 10). Notice how the bit length jumps from 8 to 9 the moment the value exceeds 255 — that jump is the same reason older systems ran out of address space at 65,535 (16 bits) or 4,294,967,295 (32 bits).

Example 4 — A large number. Enter 1,000,000. Binary is 11110100001001000000 (20 bits); octal is 3641100; the numeric hex field reads 1000000 (standard hex notation F4240). Grouping the binary into chunks of four from the right gives 1111 0100 0010 0100 0000, which maps cleanly to hex F4240 — confirming the conversion is consistent.

FAQ

How do I convert decimal to binary by hand?

Repeatedly divide the decimal number by 2 and collect the remainders, reading them from bottom to top. For 42: 42÷2=21 r0, 21÷2=10 r1, 10÷2=5 r0, 5÷2=2 r1, 2÷2=1 r0, 1÷2=0 r1. Reading the remainders upward gives 101010. The calculator does this division for you instantly.

How do I convert binary to decimal?

Write down the weight of each bit position (1, 2, 4, 8, …) and add the weights wherever the bit is 1. For 101010, add 32 + 8 + 2 = 42. To reverse this tool, keep changing the decimal input until the binary line shows the pattern you want.

What is the difference between hexadecimal and binary?

Hexadecimal (base 16) is a compact shorthand for binary (base 2). One hex digit stands for exactly four binary digits, so a byte like 1101 1010 becomes just da. Programmers use hex because it is far faster to read than a long string of ones and zeros while still mapping one-to-one onto the hardware.

How many bits do I need to represent a number?

A number n needs floor(log₂ n) + 1 bits, which the calculator reports as Bit Length. Values 0–1 need 1 bit, 2–3 need 2, 4–7 need 3, and so on. Each added bit doubles the range: 8 bits reaches 255, 16 bits reaches 65,535, and 32 bits reaches 4,294,967,295.

Why does 255 become "ff" in hexadecimal?

Because hex uses digits 0–9 followed by A–F (representing ten through fifteen). ff means fifteen sixteens plus fifteen ones = 15×16 + 15 = 255. It is the largest two-digit hex number, just as 99 is the largest two-digit decimal number.

What about negative numbers in binary?

This calculator converts non-negative (unsigned) integers. Negative integers in real systems use two's complement, which requires knowing a fixed bit width — for example, −1 in an 8-bit word is 11111111. Because the width changes the answer, enter the magnitude and consult your language's signed-integer documentation for the bit width you need.

Disclaimer

This binary calculator is provided for informational purposes only and is intended for education, prototyping, and quick reference. Conversions follow standard Python radix functions and assume non-negative integers; results may differ from signed, floating-point, or arbitrarily-wide representations used in specific languages or hardware. Always verify critical values against your target programming environment or datasheet before relying on them.

Related Calculators

Disclaimer

Results are estimates for illustration only. Verify important figures independently.