Enter Value A in any common base — prefix with 0x for hexadecimal (0xDEADBEEF), 0b for binary (0b10110010), 0o for octal (0o755), or just type a plain decimal number. The calculator displays the value in all four bases simultaneously, so you can read off the conversion at a glance.
To apply a bitwise operator, select an operation from the dropdown and enter Value B. The result also appears in all four bases. Bit width controls the precision: at 8-bit, NOT 0 is 0xFF; at 32-bit, NOT 0 is 0xFFFFFFFF. Switch sign mode to read the same bits as either an unsigned integer or a signed two's-complement value.
What Each Operation Does
AND (&): result bit is 1 only when both A and B have a 1 in that position. Used to mask off bits — e.g. x AND 0xFF isolates the low byte.
OR (|): result bit is 1 when either A or B has a 1. Used to set bits — e.g. flags OR 0x04 sets bit 2 without disturbing the others.
XOR (^): result bit is 1 when exactly one of A or B has a 1. Used to toggle bits or detect differences. x XOR x = 0 always.
NOT (~): flips every bit of A. At 8-bit width, NOT 0x0F is 0xF0.
NAND, NOR: AND-then-NOT and OR-then-NOT respectively. NAND is the universal gate — every other boolean operation can be built from NAND alone, which is why it's the foundational building block of CMOS digital logic.
Shift left (<<): multiplies by powers of two. 3 << 4 equals 48.
Logical shift right (>>): divides by powers of two, filling vacated high bits with zero. Always treats the input as unsigned.
Arithmetic shift right (>> with sign extension): divides by powers of two, filling vacated high bits with the sign bit. Preserves sign for signed values.
Real-World Uses
This calculator is what every developer reaches for during low-level work: parsing binary file formats, debugging packed bit-flags, working out subnet masks, reading hex dumps, packing colors into RGBA integers ((R << 24) | (G << 16) | (B << 8) | A), checking if a value is a power of two (x AND (x - 1) == 0), and converting Unix file permissions between octal (0o755) and the rwxr-xr-x mental model.
It's also handy for embedded work where you need to construct a control register value bit-by-bit, or for reverse engineering when an integer value in a tool's UI doesn't match the bytes in a hex editor.
Common Mistakes
Forgetting the bit width: 0xFF AND 0xFF is 0xFF at 8-bit width but the same bits at 32-bit width is just 0x000000FF. The bit width controls how the result is displayed and how operators like NOT extend.
Confusing logical and arithmetic shift right: For unsigned values they behave identically. For signed negative values, arithmetic shift preserves the sign (-8 >> 1 = -4) while logical shift gives a large positive number.
Thinking signed conversion changes the bits: It doesn't. Signed and unsigned are just two interpretations of the same bit pattern. 0xFF at 8-bit unsigned is 255 and at 8-bit signed is -1 — same byte, different read.
Frequently Asked Questions
Type a hex literal directly into the value field — 0xFF, FF, or #ff all parse to 255. Decimal numbers parse as base-10. Binary literals start with 0b (e.g. 0b1011 = 11) and octal literals start with 0o (e.g. 0o755 = 493).
Bit width clamps the value and the result to that many bits. NOT 0 at 8-bit width is 0xFF. NOT 0 at 32-bit width is 0xFFFFFFFF. Shift operations also wrap at the chosen width.
Toggle the "Signed" option. With signed two's-complement on, the high bit is treated as the sign bit — so 0xFF at 8-bit width is -1, not 255. Switch to "Unsigned" to read the same bytes as a positive integer.
Yes — the calculator uses BigInt internally so 64-bit values stay precise. Operations on 8/16/32-bit widths are also exact; the result is masked to the width before display.
AND yields 1 only where both bits are 1. NAND is the negation: 1 everywhere except where both bits are 1. NAND is the universal gate — every other boolean operator can be built from NAND alone, which is why it's the building block of digital logic.
This programmer calculator converts any integer between decimal, hexadecimal, binary, and octal instantly — and computes bitwise AND, OR, XOR, NOT, left shift, and right shift at 8-, 16-, 32-, or 64-bit width. The sections below explain the math behind each conversion, walk through a fully verifiable worked example, and cover the bitwise operator pitfalls that trip up even experienced developers.
How Number Base Conversion Works
Positional Notation Explained
Every positional numeral system assigns weight to a digit based on its position. The general formula is:
value = Σ (digit × baseposition)
For decimal 2,847: (2 × 10³) + (8 × 10²) + (4 × 10¹) + (7 × 10⁰) = 2000 + 800 + 40 + 7. The same arithmetic applies in any base — swap 10 for 16, 8, or 2 and the rule holds identically.
The Division-Remainder Algorithm
Converting a decimal number to another base uses repeated division: divide by the target base, record the remainder, then divide the quotient again until it reaches zero. Reading the remainders from last to first gives the converted digits. Remainders above 9 map to letters in hexadecimal (10→A, 11→B, … 15→F). The Decimal to Binary Calculator automates this for base-2 specifically.
Why Bases 2, 8, and 16 Are Natural Fits for Binary Hardware
The relationship 2³ = 8 means every octal digit encodes exactly three bits, and 2⁴ = 16 means every hex digit encodes exactly four bits (a nibble). These clean mappings make conversion between binary and hex — or binary and octal — trivial: substitute digits in groups of four or three without any arithmetic. That efficiency is why engineers reading memory dumps or IEEE 754 floating-point bit patterns almost always reach for hex rather than decimal.
Binary, Hexadecimal, and Octal: What Each Base Means
Binary (Base-2): The Language of Hardware
Binary digits are 0 and 1, mapping directly to the two stable states of a transistor — off and on. All digital logic ultimately reduces to binary. A CPU register holding the value 47 stores it as 00101111; every arithmetic or logic operation the chip performs happens at this level. Writing programs in binary notation is impractical beyond a few bytes, but understanding it is essential for debugging low-level code.
Hexadecimal (Base-16): Compact Bit Representation
Hex digits run 0–9 then A–F, where A=10 and F=15. One hex digit represents exactly 4 bits, so a single byte is always expressed as two hex digits — never more, never fewer. That predictability makes hex the standard notation for memory addresses, color codes, and cryptographic constants. NIST FIPS 197 (the AES specification) publishes its key schedule and round constant tables entirely in hexadecimal: the 128-bit AES key from Appendix A appears as 2b7e151628aed2a6abf7158809cf4f3c — 32 hex digits, far more scannable than the 39-digit decimal equivalent. Programmers also prefer hex for readability: 0xB1F is twelve characters shorter than its 12-bit binary expansion 101100011111.
Octal (Base-8): Unix File Permissions and Legacy Systems
Octal digits run 0–7. Unix file permissions illustrate why octal persists in modern systems: chmod 755 expresses rwxr-xr-x as three 3-bit groups — 7 = 111 (rwx), 5 = 101 (r-x), 5 = 101 (r-x). Each octal digit maps cleanly to one owner/group/other permission triplet. Outside Unix, octal appears in legacy PDP-era assembly and some network protocol constants, but hex has largely displaced it in modern use.
Worked Example: Converting 2,847 to Hex, Binary, and Octal — Then a Bitwise AND
Input A
Decimal 2,847
Input B
Decimal 3,690
Operation
Base conversion of both values; then bitwise AND
Step 1 – Decimal 2,847 to Hexadecimal
Apply the division-remainder algorithm with base 16:
Bitwise Operations: AND, OR, XOR, NOT, Left Shift, Right Shift
AND, OR, XOR: Boolean Bit-by-Bit Operations
Each bitwise operator applies a boolean rule independently to every pair of corresponding bits across two operands. The Bitwise AND/OR/XOR Calculator handles all three, but understanding the rules lets you predict results by inspection.
Bitwise Operator Truth Table (AND, OR, XOR, NOT)
A
B
A AND B
A OR B
A XOR B
NOT A
0
0
0
0
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
1
1
1
0
0
Use cases: AND → mask/clear bits; OR → set bits; XOR → toggle bits; NOT → complement
Truth table for the four fundamental bitwise operators on 1-bit inputs. For multi-bit operands, apply the rule to each bit position independently.
AND (1&1=1, 1&0=0, 0&0=0) is the standard masking operator: value & 0x0F isolates the lower nibble by zeroing the upper four bits. OR (1|0=1, 0|0=0) sets specific bits: flags |= READ turns on the READ bit without touching others. XOR (1^1=0, 1^0=1, 0^0=0) toggles bits and underlies simple XOR ciphers — XOR the same key twice to recover the original value.
NOT (Bitwise Complement)
NOT flips every bit. On an 8-bit value, ~0x0F = 0xF0 (11110000). The same operation on a 32-bit value produces 0xFFFFFFF0. This is why the bit-width selector in this calculator changes the NOT output — the result is always width-dependent.
Left Shift (<<) and Right Shift (>>)
Left shift (x << n) moves all bits toward the most significant position by n places, which is mathematically equivalent to multiplying x by 2n. The Intel IA-32 Architecture Software Developer Manual (Volume 2, SHL instruction) defines this precisely and notes that bits shifted out of the word boundary are lost. Example: 0x0F << 2 = 0b00001111 << 2 = 0b00111100 = 0x3C = 60.
Right shift comes in two flavors. Logical right shift (SHR) fills vacated high bits with 0, always producing a non-negative result. Arithmetic right shift (SAR) replicates the sign bit, preserving the sign of a negative number. The Intel SDM treats these as distinct instructions — the distinction matters whenever you shift signed integers.
Practical Code Examples
Building a bitmask for bit n: uint32_t mask = 1u << n;. Extracting a nibble from byte position p: (value >> (p * 4)) & 0x0F. Packing two bytes into a 16-bit word: uint16_t word = (high << 8) | low;. Left-shifting a 32-bit signed int by 31 places reaches the sign bit and triggers undefined behavior under ISO C11 — use uint32_t to avoid it.
Left Shift and Right Shift Examples
Expression
Decimal Input
Shift Amount
Result (Hex)
Result (Decimal)
Notes
0x0F << 2
15
2
0x3C
60
× 4
0x01 << 7
1
7
0x80
128
MSB of 8-bit byte
0xFF >> 4
255
4
0x0F
15
Upper nibble discarded
0x80 >> 3
128
3
0x10
16
÷ 8
0x0001 << 15
1
15
0x8000
32768
MSB of 16-bit word
0xB1F >> 4
2847
4
0x0B1
177
Drops lower nibble
1 << 31 (signed)
1
31
—
undefined
UB in C signed int; use uint32_t
0xF0 >> 4 (arith)
240
4
0x0F
15
SAR vs SHR same here (positive value)
Eight shift examples showing both directions. The undefined behavior row highlights the C11 constraint on left-shifting signed types into the sign bit.
Two's Complement and Signed Integer Representation
What Is Two's Complement?
Two's complement is the standard encoding for signed integers on every mainstream CPU architecture. Its defining property: the same hardware adder circuit handles both addition and subtraction without modification, because subtracting x is identical to adding the two's complement of x. The most significant bit (MSB) acts as the sign bit — when it is 1, the value is negative in a signed interpretation.
Converting a Negative Number to Two's Complement
To find the 8-bit two's complement of −47, start with the binary representation of 47: 00101111. Invert every bit: 11010000. Add 1: 11010001. So −47 stored as a signed 8-bit integer is 0xD1.
Python confirms this with masked arithmetic: bin(-47 & 0xFF) == '0b11010001' returns True. The & 0xFF mask forces Python — which uses arbitrary-precision integers — to emulate 8-bit wrapping behavior.
Signed vs Unsigned Ranges by Bit Width
Bit width determines how many distinct values fit in the register. For n bits, unsigned values span 0 to 2n−1; signed values span −2n−1 to 2n−1−1. The 32-bit signed maximum is 2,147,483,647 (INT_MAX in C/C++); exceeding it wraps to −2,147,483,648 on overflow. The 64-bit signed maximum reaches 9,223,372,036,854,775,807.
Maximum Values by Integer Width (Signed and Unsigned)
Bit Width
Signed Max (2n−1−1)
Unsigned Max (2n−1)
8-bit
127
255
16-bit
32,767
65,535
32-bit
2,147,483,647
4,294,967,295
64-bit
9,223,372,036,854,775,807
18,446,744,073,709,551,615
Signed and unsigned maximum values for common integer widths. Each step up doubles the unsigned range; the signed range shifts the same total span by half to accommodate negative values.
Common Programming Mistakes with Bitwise Operators
Operator Precedence Pitfalls
In C, the & operator has lower precedence than ==. The expression if (x & MASK == 0) is parsed as if (x & (MASK == 0)) — which tests x & 1 or x & 0, not the intended mask. Always add parentheses: if ((x & MASK) == 0). The same trap exists with | and other comparison operators.
Signed vs Unsigned Shift Confusion
Arithmetic right shift on a negative signed integer replicates the sign bit; logical right shift fills with zeros. In C89, right-shifting a negative signed integer is implementation-defined — the compiler is free to choose either behavior. For portable code, cast to unsigned before shifting: (unsigned int)value >> n. C11 and C++14 are more explicit but the cast remains the clearest signal of intent.
Integer Overflow on Shift
Left-shifting a value into or past the sign bit of a signed integer is undefined behavior under ISO C11 §6.5.7. Code like 1 << 31 on a 32-bit int may appear to work in debug builds and then break with optimizations enabled. Use 1u << 31 (unsigned literal) or UINT32_C(1) << 31 from <stdint.h>.
Misreading Hex Literals
0x0A and 0xA0 differ by a factor of 16 but look nearly identical in a long register initialization list. Write the full byte width — 0x0A rather than 0xA — when the context demands clarity. Separately, confusing | (bitwise OR, for setting bits) with & (AND, for masking/clearing bits) is a perennial embedded-systems bug: REG |= FLAG sets a bit; REG &= ~FLAG clears it.
When to Use Each Number Base in Real Programming
Binary: Bit Flags and Masks
Write permission bits in binary when you want to document which specific bit you are setting: #define READ 0x04 // 0b00000100, #define WRITE 0x02 // 0b00000010, #define EXEC 0x01 // 0b00000001. These correspond to the POSIX-style permission model. The binary comment makes the bit position self-documenting in a way that the hex constant alone does not.
Hexadecimal: Memory Addresses, Color Codes, Cryptographic Keys
GDB and most debuggers display memory addresses in hex — 0x7fff5fbff8b0 is the stack pointer on a typical macOS x86-64 process. HTML/CSS colors are 24-bit RGB packed as six hex digits: #1A2B3C encodes red=0x1A, green=0x2B, blue=0x3C. The AES-128 key is 128 bits = 32 hex digits; NIST FIPS 197 Appendix A prints all eleven round keys in hex precisely because engineers need to verify implementations byte-by-byte.
Octal: File Permissions
The chmod 0755 notation maps directly to Unix permission bits: octal 7 = binary 111 (read+write+execute for owner), octal 5 = binary 101 (read+execute for group and others). Three octal digits cover all nine permission bits cleanly, which is why POSIX standardized on this representation.
Decimal: Human-Facing Output
Use decimal for any value a user reads directly: port numbers (8080, 443), error codes in log messages, loop counters, and array indices. Mixing hex into user-visible output without clear labeling creates confusion — reserve non-decimal bases for system-level and developer-facing contexts.
Number Base Reference Tables
Decimal, Hexadecimal, Binary, and Octal Equivalents (Selected Values 0–255)
Decimal
Hexadecimal
Binary (8-bit)
Octal
0
0x00
00000000
000
1
0x01
00000001
001
7
0x07
00000111
007
8
0x08
00001000
010
9
0x09
00001001
011
10
0x0A
00001010
012
15
0x0F
00001111
017
16
0x10
00010000
020
31
0x1F
00011111
037
32
0x20
00100000
040
63
0x3F
00111111
077
64
0x40
01000000
100
100
0x64
01100100
144
127
0x7F
01111111
177
128
0x80
10000000
200
170
0xAA
10101010
252
192
0xC0
11000000
300
200
0xC8
11001000
310
254
0xFE
11111110
376
255
0xFF
11111111
377
20 representative values chosen at base boundaries (8, 16, 32, 64, 128) and common bitmask values (0xAA = alternating bits; 0xC0 = top two bits set).
Common ASCII Characters: Decimal, Hexadecimal, and Binary
Character
Decimal
Hexadecimal
Binary (8-bit)
NUL
0
0x00
00000000
Space
32
0x20
00100000
!
33
0x21
00100001
@
64
0x40
01000000
#
35
0x23
00100011
0
48
0x30
00110000
9
57
0x39
00111001
A
65
0x41
01000001
F
70
0x46
01000110
Z
90
0x5A
01011010
a
97
0x61
01100001
f
102
0x66
01100110
z
122
0x7A
01111010
DEL
127
0x7F
01111111
CR
13
0x0D
00001101
LF
10
0x0A
00001010
TAB
9
0x09
00001001
ESC
27
0x1B
00011011
+
43
0x2B
00101011
/
47
0x2F
00101111
Printable and control characters from the ASCII table. Uppercase and lowercase letters differ by exactly 0x20 (bit 5), which is why a single OR or AND toggles case.
FAQ: Programmer Calculator Questions
What is the difference between hexadecimal and binary?
Both represent exactly the same set of integer values — the difference is notation density. Binary uses base 2 with only the digits 0 and 1, while hexadecimal uses base 16 with digits 0–9 and letters A–F. Because 2⁴ = 16, one hex digit encodes exactly four binary bits, making hex four times more compact than binary for reading memory dumps, register values, and bit patterns. A 32-bit address that spans 32 binary digits collapses to just 8 hex digits.
How do I convert a decimal number to hexadecimal?
Repeatedly divide the decimal number by 16 and record each remainder. Remainders from 10 to 15 map to A through F. After the quotient reaches zero, read the remainders from last to first to get the hex digits. For 2,847: the divisions yield remainders 15 (F), 1, and 11 (B), so the result is 0xB1F. Verify by computing (11 × 256) + (1 × 16) + 15 = 2,847.
What does a bitwise AND operation do?
Bitwise AND compares each pair of corresponding bits in two operands and outputs 1 only when both input bits are 1 — otherwise it outputs 0. Its primary use is masking: applying AND with a mask zeroes out unwanted bits while leaving the desired bits unchanged. For example, value & 0x0F clears the upper four bits and isolates the lower nibble, regardless of what the upper bits contain.
Why do programmers use hexadecimal instead of decimal?
Hardware organizes data in groups of 4 or 8 bits, and one hex digit represents exactly 4 bits (a nibble), so a single byte is always exactly two hex digits. This alignment makes memory addresses, CPU register dumps, and byte-level protocol fields far more predictable to read than decimal equivalents. The decimal value 255, for instance, is immediately recognizable as 0xFF — a fully set byte — in a way the decimal form obscures.
What is a left shift operator and when is it used?
The left shift operator (<<) moves all bits in a value toward the most significant position by n places, which multiplies the integer by 2n. As documented in the Intel IA-32 Architecture Software Developer Manual (Volume 2, SHL instruction), bits shifted out of the word boundary are discarded. Common uses include building bitmasks (1u << n sets bit n), fast power-of-two multiplication, and packing multiple small values into a single integer field.
How does two's complement represent negative numbers?
Two's complement inverts all bits of the positive magnitude and adds 1. For −47 in 8 bits: start with 00101111, invert to 11010000, add 1 to get 11010001. The most significant bit being 1 signals a negative value in signed interpretation. This encoding lets CPUs reuse the same adder circuit for both addition and subtraction, which is the primary reason it became the universal standard for signed integer storage.
What is the maximum value for a 32-bit signed integer?
The maximum value is 2,147,483,647, equal to 2³¹ − 1. This is defined as INT_MAX in the C standard library header <limits.h> and applies on both 32-bit and 64-bit platforms where int is 32 bits. Incrementing past this value wraps to −2,147,483,648 — a bug that has caused real-world failures, including a well-documented overflow in a Boeing 787 power-management counter.
Why do embedded systems use bitwise operations?
Embedded microcontrollers expose hardware peripherals — GPIO pins, timers, interrupt controllers — through memory-mapped registers where each individual bit controls a distinct hardware function. Bitwise AND, OR, and XOR allow firmware to set, clear, or toggle a single pin state or configuration flag in one CPU instruction without disturbing adjacent bits in the same register. This precision is impossible with arithmetic operations alone, and it requires no library overhead — critical in environments with kilobytes of flash and no operating system.