Skip to content
TheCalcUniverse

Binary & Hex Calculator — Quick & Accurate Online Calculator & Guide

Convert between Decimal, Binary, Hex, and Octal with positional value breakdown. Perform arithmetic and bitwise operations (AND, OR, XOR, NOT, shifts).

✓ Tested formula & cited sources Formula verified 2026-01-15 Runs in your browser — inputs never sent anywhere

The formula

Binary: dₙ₋₁×2ⁿ⁻¹ + … + d₀×2⁰ | Signed: −2ⁿ⁻¹ … 2ⁿ⁻¹−1 | Unsigned: 0 … 2ⁿ−1

Base (b)
Numeral System Base
Bit Width (n)
Fixed Bit Width
Two's Complement
Two's Complement Representation
Bitwise Op, Shift
Bitwise & Shift Operations
BE / LE
Big Endian vs. Little Endian
Full explanation ↓

How Binary & Hex Works

Binary: dₙ₋₁×2ⁿ⁻¹ + … + d₀×2⁰ | Signed: −2ⁿ⁻¹ … 2ⁿ⁻¹−1 | Unsigned: 0 … 2ⁿ−1

Every number in a positional numeral system can be expressed as the sum of each digit multiplied by its base raised to the digit's position. With a fixed bit width, the leftmost bit acts as the sign bit in two's complement: 0 = positive, 1 = negative. A negative number is stored as the two's complement of its absolute value (invert all bits, add 1). Bitwise operations (AND, OR, XOR, NOT, shifts) operate on the binary representation masked to the selected width. Endianness determines the byte order in memory: big-endian stores the most significant byte first (at the lowest address), while little-endian stores the least significant byte first. x86/x64 systems use little-endian; network protocols use big-endian.

Base (b)
Numeral System BaseThe number of unique digits used. Binary = 2 (0-1), Octal = 8 (0-7), Decimal = 10 (0-9), Hexadecimal = 16 (0-9, A-F).
Bit Width (n)
Fixed Bit WidthThe number of bits used to represent a value. 8-bit: range 0-255 unsigned or -128 to 127 signed. 32-bit: 0-4,294,967,295 unsigned. 128-bit: 0-3.4×10³⁸ unsigned. Arithmetic wraps at this boundary (modulo 2ⁿ).
Two's Complement
Two's Complement RepresentationThe standard way to represent signed integers in binary. The most significant bit is the sign bit (1 = negative). To negate a number: invert all bits and add 1. For example, -1 in 8-bit is 11111111₂. Same bit pattern interpreted as unsigned is 255.
Bitwise Op, Shift
Bitwise & Shift OperationsAND, OR, XOR, NOT operate on individual bits. Left shift (<<) moves bits left (multiply by 2ⁿ), right shift (>>) moves bits right (divide by 2ⁿ, sign-extending for signed). In this calculator, bitwise ops are masked to the selected bit width.
BE / LE
Big Endian vs. Little EndianEndianness describes byte ordering in memory. Big-endian stores the most significant byte at the lowest address (network byte order). Little-endian stores the least significant byte at the lowest address (x86, x64, most ARM). The value 0x0A0B0C0D in 32-bit: big-endian = [0A, 0B, 0C, 0D], little-endian = [0D, 0C, 0B, 0A].
The same binary pattern represents different values depending on signed vs. unsigned interpretation. In two's complement, the most significant bit is the sign bit.

How to Use

  1. Select "Convert" to translate a number between bases (Decimal, Binary, Hex, Octal). The positional breakdown shows how each digit contributes.
  2. Select "Calculate" to perform arithmetic or bitwise operations between two numbers in a chosen base.
  3. Use the "Bit Width" selector to see values padded to a specific width (8 to 128 bits). With a width set, you see both signed and unsigned decimal interpretations, and two's complement binary representation for negative numbers.
  4. For bitwise operations (AND, OR, XOR, NOT, shifts), values are masked to the selected bit width before and after the operation. This lets you explore what happens in real CPU registers.
  5. For arithmetic (Add, Subtract), the calculator shows both the raw result and the wrapped (truncated to bit width) result, plus overflow and carry flags.
  6. When a bit width is selected, the byte layout table shows the value's memory representation in both big-endian and little-endian order — essential for understanding binary file formats and network protocols.
  7. Results are shown in all four bases automatically for easy cross-reference.

Understanding the Result

Number base conversion is fundamental to computing and digital electronics. Every positional numeral system works the same way: each position represents the base raised to a power (position counting from 0 at the right). Binary (base 2) uses only 0 and 1 — the language of computers. Octal (base 8) and Hexadecimal (base 16) are compact ways to represent binary data since 8 = 2³ and 16 = 2⁴. Bit width matters because computers store numbers in fixed-size registers (8, 16, 32, 64, or 128 bits). The same binary pattern can represent different values depending on whether you interpret it as signed (two's complement) or unsigned. For example, 11111111₂ in 8-bit is 255 unsigned but -1 signed. Two's complement is used because addition and subtraction work the same way regardless of sign — the same hardware circuit handles both. Overflow occurs when the result of an operation exceeds the signed range, and the carry flag indicates when the result exceeds the unsigned range. Understanding these concepts is essential for low-level programming, embedded systems, network protocol design, and digital logic.

Worked Examples

A programmer wants to understand how 127 + 1 = -128 in 8-bit signed arithmetic. They convert 127 to binary (01111111₂), add 1, and get 10000000₂ which the signed interpretation reads as -128.

mode = Calculate · base = Decimal · operation = Add · value1 = 127 · value2 = 1 · bitWidth = 8

Result is 10000000₂ = -128 signed, 128 unsigned. Signed overflow flag is set.

This demonstrates two's complement overflow — adding 1 to the maximum positive value wraps to the minimum negative value. The same bit pattern interpreted as unsigned gives 128, the correct mathematical result.

A network engineer is converting the IPv4 address 192.168.1.1 to hexadecimal to match a firewall rule. They convert each decimal octet to hex.

mode = Convert · fromBase = Decimal · toBase = Hex · value = 192

192 decimal = C0 hex. The full address 192.168.1.1 becomes C0.A8.01.01 in hex.

Networking uses hex extensively: MAC addresses are 12 hex digits, IPv6 addresses use 8 groups of 4 hex digits each, and many protocol fields are defined in hex. This conversion is essential for configuring routers, firewalls, and network monitoring tools.

Frequently Asked Questions

How do I convert between binary and hexadecimal?
Group binary digits into sets of 4 (from right to left), then convert each group: 0000=0, 0001=1, …, 1111=F. For example, 11011011₂ = 1101 1011 = DB₁₆. Going the other way, each hex digit becomes 4 binary digits. With this calculator, set From = Binary, To = Hex and the bit width to pad the output to the desired width.
What is two's complement and why is it used?
Two's complement is the standard way computers represent signed integers. The most significant bit is the sign bit (0 = positive, 1 = negative). To negate a number: invert all bits and add 1. For example, +5 in 8-bit is 00000101₂. Invert: 11111010₂. Add 1: 11111011₂ = -5. The beauty is that addition hardware works identically for signed and unsigned numbers — the same binary adder handles both, and the programmer just decides how to interpret the result. A CPU's overflow flag detects signed overflow, while the carry flag detects unsigned overflow.
What bit width should I use for my calculation?
8-bit: good for learning and practice (range -128 to 127 signed). 16-bit: common in embedded systems and older hardware (range -32,768 to 32,767). 32-bit: standard for bitwise operations in most programming languages (range -2.1×10⁹ to 2.1×10⁹). 64-bit: modern CPU architecture, memory addresses (range -9.2×10¹⁸ to 9.2×10¹⁸). 128-bit: IPv6 addresses, UUIDs, cryptography (huge range). Choose the width that matches your target system or the data type you are working with.
Why does 127 + 1 in 8-bit give -128?
Because the result (128) exceeds the maximum signed 8-bit value (127). In binary: 01111111₂ + 00000001₂ = 10000000₂. The most significant bit flips from 0 to 1, which the signed interpretation reads as -128. This is "signed overflow" — the CPU sets its overflow flag. The same bit pattern interpreted as unsigned gives 128, which is correct. This is why understanding both signed and unsigned interpretations matters when working with fixed-width arithmetic.
How does left shift relate to multiplication?
Each left shift by 1 position multiplies the number by 2. So x << 3 = x × 2³ = x × 8. The bits move into higher-value positions. However, bits shifted beyond the bit width are lost (truncated). In 8-bit: 11111111₂ (255) << 1 = 11111110₂ (254). Mathematically 255×2=510, but 510 & 0xFF = 254. Right shift (>>) divides by 2, rounding toward negative infinity for signed integers. Both behaviors match real CPU operation.
What do bitwise AND, OR, and XOR actually do?
AND: each bit is 1 only if BOTH input bits are 1. Used for masking (isolating specific bits). OR: each bit is 1 if EITHER input bit is 1. Used for setting bits. XOR: each bit is 1 if the input bits are DIFFERENT. Used for toggling bits. These three operations, combined with shifts, can implement any boolean function. They are fundamental to cryptography, graphics (color channel extraction), networking (subnet masks), and hardware register manipulation.
What is the difference between big endian and little endian?
Endianness describes the byte order of multi-byte values in computer memory. Big endian stores the most significant byte first (at the lowest memory address), like how we write numbers — 0x1234 is stored as [0x12, 0x34]. Little endian stores the least significant byte first — 0x1234 is stored as [0x34, 0x12]. x86 and x64 processors use little-endian, while network protocols (TCP/IP, HTTP) use big-endian (also called network byte order). Some architectures like ARM are bi-endian and can switch. Endianness only matters for multi-byte values — 8-bit values are always the same. When reading binary file formats or network packets, knowing the endianness is essential for correct interpretation.

Pro Tips

  • Use 8-bit mode when learning two's complement — it has only 256 possible values (-128 to 127) and the patterns are easy to memorize.
  • The AND operation with 0xFF (255 decimal, 11111111 binary) is the standard way to extract the lowest byte of a value. Use this pattern for byte-level manipulation.
  • XOR of two identical values always gives 0 — this property is used for fast register clearing (XOR EAX, EAX) and simple encryption (XOR cipher).
  • Left shift by 1 (x << 1) multiplies by 2; by n multiplies by 2^n. This is faster than multiplication on many CPUs, though modern compilers optimize `x * 8` to `x << 3` automatically.
  • Hexadecimal is more compact than binary (1 hex digit = 4 bits) and is widely used for memory addresses, color codes, and debugging. Learning to convert between binary, hex, and decimal mentally is a valuable skill.

Limitations to Know

  • This calculator handles integer arithmetic only — floating-point binary representation (IEEE 754) is a completely different format and is not supported.
  • Bit widths are limited to standard sizes (8, 16, 32, 64, 128 bits). Arbitrary bit widths and custom word sizes are not supported.
  • The calculator assumes two's complement for signed representation. Other signed integer formats (ones' complement, sign-magnitude) used in some legacy and specialized systems are not available.
  • Overflow and carry detection is based on the selected bit width. Without a bit width selected (None), no overflow or carry flags are computed.
Was this calculator helpful?
Cite this calculator

TheCalcUniverse. "Binary & Hex Calculator — Quick & Accurate Online Calculator & Guide." TheCalcUniverse, 2026, https://thecalcuniverse.com/math/binary-hex-calculator/. Accessed July 24, 2026.

Embed this calculator on your site

Free to embed. Paste this into any HTML page — it stays up to date automatically.

Open embed ↗

You may also like