Perform bitwise AND, OR, XOR, NOT, and logical shifts on exact integers with binary, decimal, hexadecimal, signed interpretation, and set-bit outputs.
Last updated
Programming bits
Bitwise calculator for AND, OR, XOR, NOT, and logical shifts
Enter unsigned integers in binary, decimal, or hexadecimal, then pick a bit width to keep
NOT and shift operations finite. The calculator shows the exact integer result in binary,
decimal, or hex without depending on floating-point rounding.
Width-controlled integer bitwise math This page treats bitwise output as an unsigned word of a fixed width. That makes NOT and
shifts readable, keeps the binary mask explicit, and avoids guessing at a language-specific
signed representation.
Quick examples
Use these presets to see common programming cases: binary flags, hex masks, width-aware
complements, and bit shifts.
Inputs may use 0b and 0x prefixes when they match the chosen
base. Spaces, underscores, and apostrophes are ignored before validation.
Enter valid integer inputs Please enter a valid unsigned integer for value A.
Bitwise operations: AND, OR, XOR, NOT, and logical shifts in binary, decimal, and hex
The bitwise calculator is for exact integer work when you need to inspect flags, masks, signed interpretations, set bits, and shifted bits instead of ordinary arithmetic. Enter values in binary, decimal, or hexadecimal, choose a width, and compare the result in binary, decimal, hex, and two's-complement signed form while keeping AND, OR, XOR, NOT, left shift, and right shift behavior explicit.
How bitwise operations work
Bitwise operators compare integer values one bit at a time. AND keeps only the bits that are 1 in both operands, OR keeps any bit that is 1 in either operand, and XOR keeps the bits that differ between the two operands. Those three operators are the core of many low-level programming tasks because they let you test, combine, and isolate flags without changing the rest of the word.
NOT flips each bit, while left shift and right shift move the bits across the selected word size. That is why a bitwise calculator is useful when you are decoding masks, reading packed settings, or checking how a value changes after a shift. The maths is still exact integer maths. The difference is that the operation happens on bit patterns instead of on decimal place values.
A & B, A | B, A ^ B, ~A, A << n, A >> n
These are the standard bitwise operators used to combine, invert, and shift integer bit patterns.
mask = 2^width − 1
A fixed-width word keeps only the bits that fit inside the chosen width.
Worked example: 11110000 AND 10101010
Using an 8-bit width, 11110000 AND 10101010 returns 10100000, which is A0 in hexadecimal and 160 in decimal. Only the positions where both inputs contain a 1 survive the AND operation, so the shared high bits remain while the alternating lower bits are cleared.
The same inputs show why the other operators matter too. OR gives 11111010, because any bit that is set in either input stays set. XOR gives 01011010, because only the positions that differ survive. Those three answers can look similar at a glance, but the bitwise calculator keeps the operator name and the width visible so the result is easy to audit.
Why width matters for NOT and shifts
NOT is the operator that causes the most confusion, because flipping every bit is not very meaningful unless you know what word size you are working with. A width-aware page solves that by masking the result to a fixed number of bits. With an 8-bit width, NOT 00001111 becomes 11110000, but with a 16-bit or 32-bit width the visible result would be longer even though the underlying integer logic is the same.
Shifts also need a width. A left shift can push bits off the left edge of the word, and a logical right shift fills new positions with zeros. If you are counting bits for flags, registers, or protocol fields, that overflow matters. The calculator therefore shows the chosen mask and keeps the dropped bits visible when a shift actually removes information.
Unsigned results, signed views, and set-bit counts
Competitor bitwise calculator pages often blur together unsigned values, signed machine integers, and visual bit diagrams. This page keeps the calculation unsigned and width-bounded, then adds a clearly labeled two's-complement signed view so you can see how the same bit pattern would be read if the selected width were treated as signed.
That distinction matters for common debugging questions such as why 11110000 is 240 as an unsigned 8-bit value but -16 as an 8-bit signed value. The calculator also reports set-bit and zero-bit counts, which helps when you are checking flags, permissions, population counts, masks, or compact protocol fields.
What this page covers and what it leaves out
This page is intentionally scoped to unsigned integer calculation with an explicit signed interpretation output. It accepts binary, decimal, and hexadecimal inputs, but it does not try to infer a programming language's overflow, arithmetic right-shift, endian, or fractional bit layout rules. Those interpretations depend on the surrounding programming language or data format, so the calculator labels the width-based signed view instead of guessing silently.
The result view is designed to make the bit pattern easy to read, not to hide it behind a generic numeric answer. That is useful when you are checking feature flags, permissions, bit masks, hashing-related values, or low-level code examples. If you need a wider radix workflow, the base calculator is the better fit; if you need direct bit logic, this page is the narrower and more precise tool.
Frequently asked questions
What is the difference between AND, OR, and XOR?
AND keeps only the bit positions that are 1 in both inputs. OR keeps any bit that is 1 in either input. XOR keeps only the positions that differ. Those three operators are the core of most bitmask, flag, and feature-toggle workflows.
Why does NOT need a bit width?
NOT flips every bit, so you need a fixed width to know which bits should be visible in the result. Without a width, the answer would not match a practical word size. This page masks the output so NOT behaves like a real finite word instead of an open-ended complement.
Is a shift the same as multiplying or dividing by two?
Left shift is equivalent to multiplying by powers of two only when the bits stay inside the chosen width. Right shift is equivalent to dividing by powers of two for non-negative integers when you are using a logical shift. The calculator shows the chosen width because overflow changes the answer once bits fall off the edge.
Can I enter binary, decimal, or hexadecimal values directly?
Yes. Choose the base for each input, then type binary digits, decimal integers, or hexadecimal values as needed. The calculator accepts common prefixes like 0b and 0x when they match the selected base, so it works well for code-style values and manual examples.
Why does the same result have an unsigned and signed value?
A bit pattern can be interpreted in more than one way. For example, 11110000 is 240 as an unsigned 8-bit value, but it is -16 when read as an 8-bit two's-complement signed value. The calculator keeps the operation unsigned and shows the signed view separately so the interpretation is explicit.
What does the set-bit count mean?
The set-bit count is the number of 1 bits in the result across the selected width. It is useful when checking flags, masks, permissions, popcount-style logic, or packed fields where the number of active bits matters as much as the decimal value.
Does this model arithmetic right shift or language-specific overflow?
No. The shift controls here are logical and width-bounded. Some programming languages distinguish sign-propagating right shift from zero-fill right shift or have fixed integer overflow rules. Use this calculator to inspect the bit pattern, then check the language or hardware rule when signed shift behavior is part of the bug.