Binary Bitwise Calculator
Calculate fixed-width binary AND, OR, XOR, NOT, shifts, bit masks, set, clear, toggle, test, field extraction, and bit-pattern comparison for registers and digital words.
DIG-006 is scoped to hardware-style fixed-width bit operations. It does not parse Boolean expressions, simulate HDL, execute user code, model CPU instruction timing, or infer device-specific register side effects.
Engineering tool
Binary Bitwise Calculator
Calculate fixed-width binary AND, OR, XOR, NOT, shifts, masks, bit mutation, bit tests, field extraction, and bit pattern differences.
Parameter panel
NOT uses Operand A only and applies a fixed-width mask.
Binary pattern; spaces and underscores are allowed.
Binary pattern; must fit the selected bit width.
Fixed-width register choices. Custom width reuses the project-wide binary limit.
Signed mode affects decimal interpretation and arithmetic right shift explanation, not raw AND/OR/XOR bit patterns.
Result console
- Binary Result
- 00001000
- Hex
- 0x08
- Unsigned Decimal
- 8
- Signed Decimal
- 8
- Bit Width
- 8bits
- Formula
- R = A AND B
Result bit positions - LSB = bit 0
Formula reference
Fixed-Width Bitwise Rules
All operations are limited to the selected word width. LSB is bit 0.
AND: R = A AND BOR: R = A OR BXOR: R = A XOR BNOT: R = Mask XOR ASet bit: R = A OR (1 << p)Clear bit: R = A AND NOT(1 << p)Toggle bit: R = A XOR (1 << p)Test bit: Bit = (A >> p) AND 1Field extract: R = (A >> s) AND ((1 << w) - 1)Difference mask: D = A XOR BHamming distance = number of set bits in DVariable definitions
- A, B
- fixed-width binary words
- Mask
- 2^n - 1 for n-bit width
- p
- bit position, using LSB = bit 0
- s
- field start bit
- w
- field width
- Logical right shift fills high bits with 0
- Arithmetic right shift copies the sign bit
- BigInt-safe logic avoids JavaScript Number 32-bit coercion
Worked Examples
AND
1010 AND 1100 = 1000.
OR
1010 OR 1100 = 1110.
XOR
1010 XOR 1100 = 0110.
8-bit NOT
NOT 10101010 inside 8 bits = 01010101.
4-bit NOT
NOT 1010 inside 4 bits = 0101.
Left Shift
00110101 << 1 in 8 bits = 01101010.
Left Shift Truncation
10000001 << 1 in 8 bits becomes 00000010 and drops a set high bit.
Logical Right Shift
10000000 logical >> 1 = 01000000.
Arithmetic Right Shift
8-bit signed 10000000 is -128; arithmetic >> 1 = 11000000, which is -64.
Set Bit
00000000 with bit 3 set becomes 00001000.
Clear Bit
11111111 with bit 4 cleared becomes 11101111.
Toggle Bit
00001000 with bit 3 toggled becomes 00000000.
Field Extraction
11010110 bits 4:2 extract 101, decimal 5.
Mask Builder
Bits 7, 3, and 0 in an 8-bit word create 10001001, hex 0x89.
Compare Patterns
10101010 XOR 11110000 = 01011010 with Hamming distance 4.
64-bit BigInt AND
Two 64-bit alternating patterns produce an exact 64-bit result without Number precision loss.
Register Engineering Example
For an 8-bit control register, suppose bit 7 is Enable, bit 3 is Interrupt Enable, and bit 0 is Mode. Setting bits 7, 3, and 0 creates mask 10001001, or 0x89. A typical engineering operation is register value OR mask, but the real device datasheet still defines reserved bits and write side effects.
Engineering Notes
- Bitwise operations act on corresponding bits in fixed-width words.
- AND is commonly used to clear or filter bits.
- OR is commonly used to set bits.
- XOR is commonly used to toggle bits or detect differences.
- NOT is always interpreted through the selected fixed-width mask.
- Logical right shift fills high bits with 0.
- Arithmetic right shift copies the sign bit.
- Signed and unsigned interpretation do not change raw AND, OR, or XOR output patterns.
- Register masks are often displayed in hexadecimal because datasheets and firmware code are easier to read that way.
- This calculator does not simulate write-1-to-clear, read-only, self-clearing, or reserved register side effects.
Common Mistakes
- Confusing logical AND with bitwise AND.
- Ignoring bit width.
- Using ordinary JavaScript Number bitwise operators for 64-bit values.
- Forgetting to mask the result after NOT.
- Treating arithmetic right shift as logical right shift.
- Treating logical shift as signed division.
- Numbering bits from 1 instead of using LSB = bit 0.
- Extracting the wrong register field because start bit and field width were swapped.
- Building a mask with the wrong word width.
- Confusing signed and unsigned decimal interpretation.
- Ignoring truncated bits after left shift.
- Changing reserved register bits without checking the device datasheet.
Support reference
FAQ
What is a bitwise operation?
A bitwise operation compares or modifies each bit in a fixed-width binary word rather than treating the input as a whole decimal number.
What is the difference between logical AND and bitwise AND?
Logical AND evaluates true or false conditions. Bitwise AND compares corresponding bits and returns 1 only where both input bits are 1.
How does a bit mask work?
A bit mask is a binary pattern used to select, set, clear, toggle, or extract specific bit positions in a register or digital word.
How do I set a bit in a register?
Build a mask with a 1 at the target bit position, then combine the register value with the mask using bitwise OR.
How do I clear a bit?
Build a one-bit mask, invert it inside the fixed word width, then apply bitwise AND to force that position to 0.
How do I toggle a bit?
Apply XOR with a mask that contains 1 at the target bit position. A 0 becomes 1 and a 1 becomes 0.
What is the difference between logical and arithmetic right shift?
Logical right shift fills high bits with 0. Arithmetic right shift copies the sign bit so signed negative values remain negative.
Why does bit width matter for NOT?
NOT must be limited by a fixed-width mask. Without a width, integer NOT has sign-extension semantics that do not match a finite hardware register.
What is LSB bit 0?
LSB bit 0 means the least significant bit, the rightmost bit in the displayed binary word, is numbered as bit position 0.
How do I extract a bit field from a register?
Shift the register right by the start bit, then apply a field-width mask such as (1 << fieldWidth) - 1.
What is Hamming distance between bit patterns?
Hamming distance is the number of bit positions that differ between two fixed-width binary words.
Why should BigInt be used for 64-bit bitwise calculations?
JavaScript Number bitwise operators use 32-bit signed coercion. BigInt keeps 64-bit and custom-width register patterns precise.
Related Calculators
Binary Arithmetic Calculator
AvailableCalculate fixed-width binary arithmetic, carry, borrow, and overflow.
Open calculatorTwo's Complement Calculator
AvailableEncode, decode, negate, and sign-extend two's-complement binary patterns.
Open calculatorLogic Gate Truth Table Calculator
AvailableGenerate truth tables for AND, OR, XOR, NOT, NAND, NOR, and XNOR gates.
Open calculatorHex Decimal Binary Converter
AvailableConvert number bases for firmware debugging and register inspection.
Open calculatorGray Code Converter
AvailableConvert Binary-Reflected Gray Code and analyze adjacent state transitions.
Open calculatorCounter & Modulus Calculator
AvailableCalculate counter modulus, unused states, wraparound, and cascaded counter sizing.
Open calculatorRelated Engineering Guides
Planned Guide
Bitwise Operations Explained
Planned Guide
Using Bit Masks in Embedded Systems
Planned Guide
How to Set and Clear Register Bits
Planned Guide
Logical vs Arithmetic Shift
Planned Guide
Signed vs Unsigned Bit Patterns
Planned Guide
