Binary & Hex Calculator
Convert between Decimal, Binary, Hex, and Octal with positional value breakdown. Perform arithmetic and bitwise operations (AND, OR, XOR, NOT, shifts) across all bases.
Binary & Hex
Results update instantly as you type
Enter Values
Embed Code
Copy and paste this HTML snippet into any web page to embed this calculator directly.
<iframe src="http://127.0.0.1:54963/embed/math/binary-hex-calculator?ref=embed" title="Binary & Hex Calculator" width="100%" style="max-width:600px; border:none; height:500px;" loading="lazy"></iframe>
Direct Link
Share this link to let others open the calculator in their browser.
The Formula
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.
Variable Definitions
Numeral System Base
The number of unique digits used. Binary = 2 (0-1), Octal = 8 (0-7), Decimal = 10 (0-9), Hexadecimal = 16 (0-9, A-F).
Fixed Bit Width
The 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 Representation
The 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 & Shift Operations
AND, 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.
Big Endian vs. Little Endian
Endianness 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].
How to Use This Calculator
- 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.
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.
Understanding the Concept
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.
Frequently Asked Questions
Sources & References
Related Calculators
Reviews
No reviews yet. Be the first to share your experience with Binary & Hex Calculator.
Write a Review
