Bitwise Operations Calculator
Calculate fixed-width bitwise masks, shifts, rotations, flag tests, signed readouts, and bit-lane changes with binary and hex checks.| Format | Value | Copy |
|---|---|---|
| {{ row.label }} | {{ row.value }} |
| Bit | A | {{ needsOperandB ? 'B/mask' : 'Operand' }} | Result | Transition | Role | Copy |
|---|---|---|---|---|---|---|
| {{ row.bit }} | {{ row.a }} | {{ row.b }} | {{ row.r }} | {{ row.transition }} | {{ row.role }} |
| Check | Finding | Next use | Copy |
|---|---|---|---|
| {{ row.check }} | {{ row.finding }} | {{ row.nextUse }} |
| Width | Unsigned | Hex | Status | Copy |
|---|---|---|---|---|
| {{ row.width }} | {{ row.unsigned }} | {{ row.hex }} | {{ row.status }} |
| Field | Value | Copy |
|---|---|---|
| {{ row.label }} | {{ row.value }} |
Introduction:
A single integer can carry far more than a count. Permissions, packet flags, file headers, device registers, color channels, checksum words, and compact option fields often pack many small facts into one stored value. Reading that value as decimal alone hides the important detail: which bit positions are set, which are clear, and which positions are supposed to mean something in the surrounding format.
Bitwise work reads the integer as a fixed set of lanes. Bit 0 is usually the least significant bit, the highest lane may be a sign bit in a signed reading, and a small group of adjacent bits can represent a field. A mask selects lanes for inspection or change. The same stored pattern can therefore be a decimal number for code, a hexadecimal value for a dump, and a binary pattern for debugging.
The main operations are small but easy to misread. AND keeps shared one bits, OR turns on any one bits found in either value, XOR marks differences, and NOT flips every lane inside the selected width. Shifts move bits left or right and may discard bits that leave the register. Rotations wrap those exiting bits around the boundary instead, which is why width must be chosen before comparing rotate results.
- Bit index
- The position of a bit, usually counted from the least significant bit as bit 0.
- Mask
- A pattern used to keep, set, clear, toggle, or test selected bit positions.
- Register width
- The number of lanes that exist for the operation, such as 8, 16, 32, 64, 128, or 256 bits.
Width is the detail that makes many correct results look wrong at first. In an 8-bit field, ~0x0F means the other four bits of the byte, so it reads as 0xF0. In a 16-bit field, the same complement reads as 0xFFF0. The operation did not change; the register gained eight more lanes.
A common mistake is to copy the final decimal value without checking the pattern that produced it. 240, 0xF0, and 11110000 can describe the same stored byte, but each view serves a different job. The integer fits code and logs, hexadecimal is compact for tickets and register notes, and binary exposes the exact lanes.
Bitwise arithmetic does not decide what a flag means in a protocol, permission model, or device. It shows whether selected positions are set, cleared, moved, preserved, or changed under a chosen rule. The external specification still decides whether a lane represents read access, an error condition, a reserved field, or a value that should not be modified.
How to Use This Tool:
Start by matching the source value. A mask from code, a packet dump, a register table, and a log line can all use different base and width conventions, so keep those details stable until the result explains why they should change.
- Enter the main value in Operand A. Auto base accepts prefixed literals such as
0b10101010,0o377, and0xFF. Choose Binary, Octal, Decimal, or Hexadecimal when a bare value such as1010needs a forced meaning. - Choose Operation. Logic operations use Operand B / mask; shifts and rotations use Shift / rotate count; set, clear, toggle, and test use Bit index. NOT uses only Operand A.
- Set Register width before judging complements, shifts, rotations, or signed readings. Auto chooses a byte boundary up to 256 bits, fixed choices cover common widths, and Custom accepts a 2 to 256 bit window.
- Open Advanced when display details matter. Digit grouping, byte order preview, prefixes, hex casing, and signed readout affect how the same stored pattern is shown, copied, and compared.
- Use the summary as a first check. The large value is the hexadecimal result, and the badges confirm the operation, active width, set-bit count, and changed-bit count.
- If a warning appears, fix the literal before trusting the result. Empty operands, invalid digits for the selected base, and mismatched prefixes such as
0xwith Binary selected are rejected rather than silently reinterpreted. - Move to the result view that matches the job: Multi-base Result for decimal, hex, binary, octal, byte stream, signed, and count rows; Bit Impact Map for lane-by-lane changes; Operation Guidance for next-use cues; Width Audit for comparison widths; Bit Density Profile for set-bit counts; and Input Snapshot or JSON when settings need to travel with the result.
Interpreting Results:
Read the fixed-width bit pattern before relying on a decimal number. Hexadecimal is compact enough for tickets and code reviews, binary shows the actual lanes, and the active-width badge tells you where complements, shifts, rotations, and signed readings were clipped.
| Output cue | What to check | Why it matters |
|---|---|---|
| Active width | Confirm the result uses the same bit count as the code, register, packet field, or example you are matching. | The same input can produce different NOT, NAND, NOR, XNOR, shift, rotation, and signed results at different widths. |
| Hexadecimal and Binary | Compare the compact hex value with the full lane pattern. | Hex is convenient for copying, while binary exposes exactly which positions are set or clear. |
| Changed from A | Count how many positions differ between Operand A and the result. | A nonzero count tells you the operation modified the pattern; the bit map shows where. |
| Decimal signed two's complement | Use this row only when the selected width matches the signed integer you want to model. | A set sign bit can turn a large unsigned value into a negative signed reading. |
| Width Audit | Compare common widths when the expected result is unclear. | Width-sensitive operations often reveal the intended byte, word, dword, qword, or wide-register context. |
| Test bit status | Treat the result as a selected-position check, not as proof of a named permission. | Only the external format or application documentation can attach a business meaning to that bit. |
A result can be mathematically correct and still be the wrong answer for your system. The usual cause is a mismatch between the selected width, the source language's shift rule, or the bit numbering used by the document you are reading. Check those details before copying a mask into production code or a hardware note.
Technical Details:
Bitwise logic works on aligned positions. AND, OR, and XOR evaluate the matching lane from two operands. Complemented forms first compute the lane result, then flip the bits inside the selected width. Single-bit operations build a one-bit mask from the chosen index, where bit 0 is the least significant bit.
A fixed-width register turns an unlimited mathematical integer into a stored unsigned pattern. Values outside the range wrap modulo 2^N, where N is the active width. That same stored pattern can then be displayed as unsigned decimal, signed two's complement, hexadecimal, octal, binary, or an ordered byte stream.
Formula Core
For width N, all-ones mask M, mathematical input V, and stored unsigned value U, the core fixed-width rules are:
With N = 8, the mask is 255. The input 0x0F stores as 15, so NOT flips the eight lanes and clips the result to 0xF0. The unsigned reading is 240. The signed reading is 240 - 256 = -16 because the high bit is set.
| Operation family | Rule inside the selected width | Typical use |
|---|---|---|
| AND, OR, XOR | Evaluate matching lanes from A and B. | Extract fields, combine flags, or find differences between patterns. |
| AND-NOT, NAND, NOR, XNOR, NOT | Invert a selected value or intermediate result, then clip with the width mask. | Clear masks, find unused positions, or inspect equality and complement patterns. |
| Left shift | Move bits toward more significant positions, fill low positions with zero, and discard overflow. | Build masks, align fields, or model unsigned scaling where overflow is clipped. |
| Arithmetic right shift | Read A as signed, shift right, preserve the sign, and wrap back to the selected width. | Match signed integer behavior where negative values remain negative after shifting. |
| Logical right shift | Shift right and fill high positions with zero. | Match unsigned packet fields, register values, and zero-fill right-shift rules. |
| Rotate left or right | Move bits around the register boundary; the count is reduced modulo the width. | Inspect circular shifts used in checksums, hashes, ciphers, and packed words. |
| Set, clear, toggle, test bit | Build a one-bit mask from the chosen bit index and apply it to Operand A. | Model flag updates and single-position condition checks. |
| Rule | Accepted range or behavior | Practical effect |
|---|---|---|
| Input bases | Binary, octal, decimal, and hexadecimal, with optional sign and visual separators. | Values from code, logs, and register notes can usually be pasted without manual cleanup. |
| Base prefixes | 0b, 0o, and 0x are accepted in Auto mode; forced base rejects mismatched prefixes. |
A hex-looking value is not silently parsed as binary or decimal. |
| Auto width | Uses enough bits for the entered values and selected operation, rounded to a byte boundary, up to 256 bits. | Ordinary inputs stay readable while width-sensitive behavior remains visible. |
| Custom width | Clamped to 2 through 256 bits. | Wide masks remain usable without generating oversized bit maps. |
| Shift and rotate count | Accepted from 0 through 255; rotations use the count modulo the active width. | A 20-bit rotate in an 8-bit register behaves like a 4-bit rotate. |
| Bit index | Accepted from 0 through 255 and clamped inside the active width. | Single-bit operations always address a lane inside the selected register. |
Privacy Notes:
The calculation is produced in the browser. Operands, masks, bit indices, shift counts, and result rows do not need a separate server calculation.
- Configured settings can appear in the page address, so avoid sharing a link that contains private masks, register dumps, or proprietary test values.
- Copied rows and downloaded artifacts can include operands, settings, and results. Review them before attaching them to tickets or public posts.
- The result explains bit patterns. It is not a security review of a protocol, cipher, permission model, or production device state.
Worked Examples:
Mask the low nibble
Enter 0b10101010 as Operand A, choose A AND B (&), enter 0x0F as Operand B / mask, and use an 8-bit width. Hexadecimal becomes 0x0A, Binary becomes 0b0000 1010 when nibble grouping is on, and Changed from A reports 2 of 8. The high-nibble one bits were cleared because the mask kept only the low four lanes.
Clear two permission flags
Enter 0b01110111, choose A AND NOT B (clear mask), and enter 0b00010010 with an 8-bit width. The result is 0x65, or 0b0110 0101 with nibble grouping. AND-NOT preserves Operand A except where the mask has one bits, so bits 4 and 1 are cleared.
Rotate a 16-bit word
Enter 0x1234, choose Rotate A left (ROL), set Shift / rotate count to 4, and use a 16-bit width. Hexadecimal becomes 0x2341. A left shift would discard the high nibble, but a rotate wraps it into the low nibble.
Compare arithmetic and logical right shift
Enter 0xF0000000 with a 32-bit width and shift by 4. With A logical right shift (>>>), Hexadecimal becomes 0x0F000000 because zeroes enter from the left. With A arithmetic right shift (>>), the sign bit is preserved and the result reads as 0xFF000000.
Fix a base mismatch warning
If Operand A is 0xFF and Input A base is forced to Binary, the value is rejected because the prefix does not match the selected base. Switch Input A base to Auto or Hexadecimal, then confirm Decimal unsigned reports 255 at an 8-bit width. If the intended binary value was 11111111, remove the hex prefix and keep Binary selected.
FAQ:
Why does NOT change when I change width?
NOT flips every bit inside the selected register. At 8 bits, ~0x0F becomes 0xF0; at 16 bits, it becomes 0xFFF0. The width badge is the first thing to check when complemented results look too large or too small.
What is the difference between arithmetic and logical right shift?
Arithmetic right shift preserves the sign bit after reading Operand A as signed. Logical right shift fills high positions with zero. They often match for non-negative patterns and diverge when the sign bit is set.
Can I paste grouped values?
Yes. Spaces, underscores, commas, and apostrophes are ignored inside numeric literals, so grouped values such as 0b1010_1100, 0xFF FF, or 1,024 can be entered directly.
Why does a bare value like 1010 read as decimal?
Auto base treats unprefixed digits as decimal. Force Binary when 1010 is meant to represent ten bits or add the 0b prefix for an explicit binary literal.
Can I model values wider than 64 bits?
Yes. Fixed and custom widths can reach 256 bits, which is useful for wide masks, block-sized fields, and large packed values. The bit map and exports stay limited to that selected width.
Does a set test bit mean a permission is enabled?
It means the selected bit position is set in the selected width. The application, protocol, or device documentation still decides which named permission or flag that bit represents.
Glossary:
- Operand
- An integer value used by a bitwise operation.
- Mask
- A bit pattern used to keep, set, clear, toggle, or test selected positions.
- Register width
- The number of bit positions available for the stored pattern.
- Least significant bit
- The lowest-value bit, normally numbered as bit 0.
- Sign bit
- The highest bit when the register is interpreted as a signed two's-complement value.
- Two's complement
- A signed-integer reading where values with the sign bit set represent negative numbers.
- Logical right shift
- A right shift that fills newly opened high positions with zero.
- Arithmetic right shift
- A right shift that fills newly opened high positions with copies of the sign bit.
- Rotate
- A circular shift where bits leaving one end of the register re-enter at the other end.
References:
- Java Language Specification, Chapter 15: Expressions, Oracle, Java SE 26, February 3, 2026.
- Bitwise and shift operators, Microsoft Learn, January 24, 2026.
- Unsigned right shift (>>>), MDN Web Docs, July 8, 2025.