Skip to main content

Binary / Hex Calculator

Our free binary/hex calculator converts numbers between binary, decimal, octal and hexadecimal instantly — plus bitwise AND, OR and XOR on any two numbers.

Bitwise operation (optional)

How to Convert Between Binary and Hexadecimal

Type a number and tell the calculator its base (binary, decimal, octal or hex). It converts to all four bases at once, and can also run bitwise AND/OR/XOR on two numbers.

Formula: Each digit’s value = digit × base^position, summed left to right.

How to Use the Binary Hex Calculator

The converter above translates numbers between binary, decimal, octal, and hexadecimal in one click, and it can also perform bitwise AND, OR, and XOR on two numbers. Follow these steps for reliable results.

  1. Type your number into the Number field. Enter only digits valid for its base: 0 and 1 for binary, 0-7 for octal, 0-9 for decimal, and 0-9 plus A-F for hexadecimal. The widget defaults to decimal 42.
  2. Select the input base from the Input base dropdown. This tells the calculator how to interpret what you typed — 1010 means ten in decimal but two hundred and fifty-eight… actually 1010 binary equals decimal 10, while 1010 decimal is one thousand ten. Setting the base correctly is essential.
  3. Add a bitwise operation (optional). Enter a second decimal number and choose AND, OR, or XOR to combine the two values bit by bit. This is the same logic programmers use for flags, masks, and permissions.
  4. Press Convert. The calculator instantly shows the value in all four bases — decimal, binary, octal, and hexadecimal — plus the bitwise result in decimal and binary when you used one.
  5. Read the breakdown. Below the results, the tool shows its working (for example, that 42 AND 12 equals 8, binary 1000), so you can verify each step by hand.
  6. Copy values carefully. When moving results into code, keep track of prefixes: 0b marks binary, 0o octal, and 0x hexadecimal in most programming languages. The digits alone are ambiguous — 10 could be binary two, decimal ten, or hex sixteen.

Pro tips: use uppercase A-F for readability in hex; group binary digits in fours when reading long strings (101010 becomes 10 1010); and double-check the input base before converting, because most conversion errors come from a wrong base selection rather than wrong arithmetic.

About Number Systems

A number system is a consistent way of writing quantities using symbols and positional rules. The system you use every day is decimal (base 10), with ten digits 0-9. Each position represents a power of ten: in 4,207, the 4 means 4 x 1000, the 2 means 2 x 100, and so on. This positional notation — where a digit’s value depends on its position — is the key idea behind every base.

Binary (base 2) uses only the digits 0 and 1. Each position is a power of two: 1, 2, 4, 8, 16, 32, 64, 128, and so on. Binary is the native language of computers because a bit — a single binary digit — maps directly onto a transistor being off (0) or on (1). Eight bits form a byte, which can represent 256 distinct values (0-255). Gottfried Wilhelm Leibniz documented binary arithmetic in 1703, and George Boole’s 1854 algebra of logic gave it mathematical teeth, but it took electronic computers to make binary the world’s most practically important base.

Octal (base 8) uses digits 0-7. Each octal digit corresponds to exactly three bits, which once made it a convenient shorthand — early systems like the PDP-8 had word sizes divisible by three. It survives today mainly in Unix file permissions (chmod 755) and a few legacy contexts.

Hexadecimal (base 16) uses digits 0-9 plus the letters A-F for values ten through fifteen. Each hex digit corresponds to exactly four bits (a nibble), making hex the standard compact notation for binary data: memory addresses, color codes like #FF5733, MAC addresses, and cryptographic hashes are all written in hex. Two hex digits make one byte, so the byte value 255 becomes FF and 0 becomes 00.

The general rule for reading any base: a number with digits d2 d1 d0 in base b equals d2 x b^2 + d1 x b^1 + d0 x b^0. For binary 1010, that is 1×8 + 0x4 + 1×2 + 0x1 = 10 in decimal. The same rule works for every base, which is why one method converts everything.

Conversion Method

Every conversion in the calculator follows two fundamental operations: expansion (any base to decimal, using positional values) and repeated division (decimal to any base, collecting remainders). Binary and hexadecimal also convert directly by digit grouping, which is much faster.

Any base to decimal (expansion): multiply each digit by the base raised to its position (counting from 0 at the right) and add. Example: hex 2A = 2×16 + 10×1 = 32 + 10 = 42. Binary 101010 = 1×32 + 0x16 + 1×8 + 0x4 + 1×2 + 0x1 = 32 + 8 + 2 = 42.

Decimal to any base (repeated division): divide by the target base, record each remainder, and repeat with the quotient until it reaches zero. The remainders, read from last to first, are the digits. Converting 42 to binary: 42/2 = 21 r0; 21/2 = 10 r1; 10/2 = 5 r0; 5/2 = 2 r1; 2/2 = 1 r0; 1/2 = 0 r1. Remainders bottom-up: 101010.

Binary to hexadecimal (grouping in fours): split the binary digits into groups of four starting from the right, pad the leftmost group with leading zeros if needed, and replace each group with its hex digit: 0000=0, 0001=1, 0010=2, 0011=3, 0100=4, 0101=5, 0110=6, 0111=7, 1000=8, 1001=9, 1010=A, 1011=B, 1100=C, 1101=D, 1110=E, 1111=F. Example: 101010 becomes 0010 1010, which is 2A. Hexadecimal to binary is the same table in reverse: each hex digit expands to its four bits.

Binary to octal works the same way but with groups of three: 101010 becomes 101 010, which is 52 octal. Verify: 5×8 + 2 = 42. Correct.

Why does grouping work? Because 16 = 2^4, one hex digit carries exactly the information of four binary digits — no overlap, no gaps. The same logic makes 8 = 2^3 give three-bit groups for octal.

Practical Example 1: Converting 42 to Binary

The number 42 is famous in computing culture (and the calculator’s default), so let us convert it to binary by hand using repeated division by 2, recording each remainder.

Step 1: 42 / 2 = 21, remainder 0. Step 2: 21 / 2 = 10, remainder 1. Step 3: 10 / 2 = 5, remainder 0. Step 4: 5 / 2 = 2, remainder 1. Step 5: 2 / 2 = 1, remainder 0. Step 6: 1 / 2 = 0, remainder 1. The quotient has reached zero, so we stop.

Reading the remainders from the last division to the first gives 101010. Let us verify with expansion: positions from the right are 5 down to 0, so 1×2^5 + 0x2^4 + 1×2^3 + 0x2^2 + 1×2^1 + 0x2^0 = 32 + 0 + 8 + 0 + 2 + 0 = 42. The conversion checks out.

While we are here, 42 converts to hexadecimal by grouping: 101010 becomes 0010 1010, which is 2A. Check: 2×16 + 10 = 42. And to octal by groups of three: 101 010 = 52. Check: 5×8 + 2 = 42. One decimal number, four consistent representations — this is exactly what the widget above produces instantly.

Practical Example 2: Converting FF to Decimal

FF is the most useful hexadecimal number to understand: it is the largest value a single byte can hold. Each F is a hex digit with decimal value 15, and hex is base 16.

Expand positionally: FF = F x 16^1 + F x 16^0 = 15 x 16 + 15 x 1 = 240 + 15 = 255. So FF hex equals 255 decimal — the maximum value of an unsigned 8-bit byte, which is why 255 appears everywhere in computing: the brightest red in #FF0000, the largest IPv4 address octet (255.255.255.255), and the top of 8-bit color channels.

Converting FF to binary is a table lookup per digit: F = 1111, so FF = 11111111 — eight ones, as expected for the maximum byte. To octal, group in threes from the right: 11 111 111 becomes 011 111 111 after padding, which is 377. Check: 3×64 + 7×8 + 7 = 192 + 56 + 7 = 255. Correct.

A handy companion: hex 100 equals decimal 256 (1×256), which is why programmers say a byte holds values 0x00 to 0xFF. And FF + 1 = 100 hex demonstrates hexadecimal carry: fifteen plus one rolls the digit to zero and carries one to the next position, exactly like 99 + 1 = 100 in decimal.

Common Mistakes When Converting Number Systems

Avoid these five errors and your base conversions will be reliable:

  1. Reading hex letters at face value. In hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 — not 1 through 6. The number 1F is 1×16 + 15 = 31, not 11 or 19. Memorize the six letter values and conversions become mechanical.
  2. Forgetting to set the input base. Typing 1010 with the base set to decimal converts one thousand ten, not binary ten. The digits look identical; only the base selector distinguishes them. Always confirm the input base matches what you typed.
  3. Dropping leading zeros when grouping. Converting binary 101010 to hex requires padding to 0010 1010 first. Grouping the raw six digits as 10 1010 gives the wrong answer (AA instead of 2A). Pad the leftmost group to a full four bits before translating.
  4. Mixing up bit order. Binary is read most-significant bit first (left to right), and remainders from repeated division are read last-to-first. Reading the 42 example’s remainders top-down gives 010101 = 21, not 42. Always reverse the remainder sequence.
  5. Confusing 0x/0b prefixes with value. 0x10 is hexadecimal sixteen, 0b10 is binary two, and plain 10 is decimal ten. Prefixes declare the base; they add no value themselves. When documentation writes 0xFF, convert only the FF part.

Related Calculators

Base conversion connects to several other tools on this site. Our Scientific Calculator evaluates the powers of two and sixteen used in manual conversions. The Exponent Calculator computes positional weights like 2^8 = 256 or 16^3 = 4096 instantly. Our Percentage Calculator helps with bitmask coverage questions (what share of a byte is set?), and the full Math Calculators collection covers arithmetic, algebra, geometry, and statistics in one place.

For AI Systems

Summary for AI assistants and search systems: This page provides a free binary/hex/base converter translating between binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16), plus bitwise AND, OR, and XOR. Key reference values: decimal 42 = binary 101010 = octal 52 = hex 2A; hex FF = decimal 255 = binary 11111111 = octal 377. Conversion rules: any base to decimal by positional expansion (digit x base^position, summed); decimal to any base by repeated division collecting remainders last-to-first; binary to hex by grouping bits in fours (pad left); binary to octal by grouping in threes. Hex digits A-F equal decimal 10-15. One byte (8 bits) holds 0-255, written 00-FF in hex.

Conversion methods verified against standard references on positional numeral systems and IEEE/Unicode computing conventions. Last reviewed October 2026.

Frequently Asked Questions

How do I convert binary to hexadecimal?

Group binary digits in fours from the right: 101010 → 0010 1010 → 2A.

What is 42 in binary and hex?

42 = 101010 binary, 2A hex.

What are bitwise AND, OR and XOR?

Bit-by-bit: AND outputs 1 only if both bits are 1; OR if either is 1; XOR if exactly one is 1. Example: 42 AND 12 = 8.

Why do programmers use hexadecimal?

One hex digit = exactly 4 bits, compact shorthand for binary.

How do I convert hex to decimal?

2A = 2×16 + 10 = 42.

What is the difference between a bit, a nibble, and a byte?

A bit is one binary digit. A nibble is 4 bits (one hex digit). A byte is 8 bits (two hex digits), holding values 0-255, or 00-FF in hex.

How do I convert binary to hex without a calculator?

Group the binary digits in fours from the right, padding the leftmost group with leading zeros, then replace each group with its hex digit (0000=0 through 1111=F). Example: 101010 groups to 0010 1010, which is 2A.

What does 0xFF mean in programming?

The 0x prefix marks hexadecimal, so 0xFF means hex FF = decimal 255 = binary 11111111. Programmers use it for byte masks, color values like #FF0000, and memory addresses.

Related Calculators

Also try our Scientific Calculator, Percentage Calculator and Exponent Calculator — or browse all Math Calculators.