Skip to content
BCBinary Code Translator
Menu

Width-aware bit operations

Bitwise Calculator

Apply AND, OR, XOR, NOT, left shift, and right shift to 8, 16, 32, or 64-bit values with explicit signed and unsigned interpretation.

Bit masks and shifts are evaluated locally with exact BigInt arithmetic.

Fixed-width bits

No result yet

Padded hexadecimal

No result yet

Unsigned decimal

No result yet

Signed decimal

No result yet

Bitwise operations with explicit width

Bitwise operations work on corresponding bits rather than on decimal digits. AND keeps a bit only when both inputs contain 1, OR keeps it when either input contains 1, XOR keeps it when the inputs differ, and NOT flips every bit. Shifts move a pattern left or right. These operations are fundamental for masks, flags, permissions, color channels, protocol fields, low-level optimization, and systems programming.

Width cannot be an afterthought. NOT 00000000 is 11111111 in eight bits, but it is sixteen ones in sixteen bits. Left shifts can discard high bits, and signed right shift can replicate the sign bit. This calculator requires 8, 16, 32, or 64 bits, masks every result to that width, and reports both signed and unsigned decimal interpretations of the final pattern.

How to use the bitwise calculator

Set the width and semantics before interpreting the operands.

  1. Choose AND, OR, XOR, NOT, left shift, or right shift.
  2. Select decimal, binary, or hexadecimal input. Decimal semantics determine whether negative values are accepted and how right shift behaves.
  3. Choose unsigned or signed two’s-complement interpretation, then choose 8, 16, 32, or 64 bits.
  4. Enter value A. Enter value B for binary operations, or a non-negative decimal shift count for shifts. NOT uses only value A.
  5. Press Calculate and compare the padded bits, hex, unsigned decimal, and signed decimal results.

Bitwise examples

The following examples use eight bits to make masking and sign behavior visible.

Operation Result bits Explanation
10101010 AND 11001100 10001000 Only positions that are 1 in both operands remain set.
10101010 OR 11001100 11101110 A position is set when either input contains a 1.
10101010 XOR 11001100 01100110 A position is set when the two input bits differ.
NOT 00001111 11110000 Every bit is flipped within the selected eight-bit mask.
10000001 << 1 00000010 The high bit is discarded and a zero enters on the right.
11111110 >> 1 11111111 signed / 01111111 unsigned Arithmetic signed shift extends the sign bit; logical unsigned shift inserts zero.

Input formats and semantics

Decimal mode validates against the selected interpretation. Unsigned eight-bit input ranges from 0 to 255. Signed eight-bit input ranges from -128 to 127 and is converted to its two’s-complement pattern before the operation. Binary and hex modes are treated as raw non-negative bit patterns and must fit within the chosen width; signedness affects result interpretation and right-shift behavior.

Shift counts are always non-negative decimal integers, regardless of the operand format. Left shift discards bits that move past the selected width and inserts zeros on the right. Unsigned right shift inserts zeros on the left. Signed right shift interprets A as a two’s-complement signed value and extends its sign.

  • Binary input accepts 0b prefixes plus spaces or underscores.
  • Hex input accepts 0x prefixes and is padded in the result to the selected width.
  • AND, OR, and XOR operate on raw patterns; signedness changes only decimal interpretation.
  • A shift count greater than or equal to the width produces zero for left/logical right shifts; arithmetic right shift of a negative value remains all ones.

How masking and shifts are implemented

Each operand is converted to an unsigned BigInt pattern between zero and 2ⁿ-1. AND, OR, and XOR combine those patterns directly. NOT first flips the unbounded BigInt bits and then applies an n-bit mask, ensuring that only the selected register width remains.

Left shift moves the pattern by the requested count and applies the mask, which models high-bit truncation in a fixed-width register. Logical right shift operates on the unsigned pattern. Arithmetic right shift first interprets the pattern as signed by subtracting 2ⁿ when the sign bit is set, then uses sign-propagating shift and masks the result back to n bits.

The final pattern is always displayed in four forms: exactly n binary digits, exactly n/4 hexadecimal digits, unsigned decimal, and signed two’s-complement decimal. This makes the operation and its interpretation independently visible.

Practical uses

Bitwise tools are most useful when individual flags or fields carry independent meaning.

Apply masks and flags

Check whether permissions or feature flags are set, combine options with OR, clear fields with AND masks, or toggle bits with XOR.

Decode packed protocol fields

Separate headers, status words, device registers, and binary file fields while preserving an exact documented width.

Work with colors and channels

Extract or combine packed RGB/ARGB channel values and verify shifts used to place bytes into a larger integer.

Test systems code

Create reference results for firmware, parsers, cryptographic preprocessing, hash code, and cross-language shift behavior.

Common mistakes and edge cases

Bitwise results often look wrong when the width or signedness differs from the system being modeled.

Forgetting the mask width

NOT and left shift are undefined without a boundary in ordinary mathematical integers. Match the width used by the register, protocol, or source language.

Mixing arithmetic and logical right shift

Negative signed values replicate a 1 during arithmetic shift. Unsigned values insert zero. Select semantics deliberately.

Entering signed binary text

Binary and hex inputs are raw patterns and do not accept a minus sign. Use signed decimal mode for a mathematical negative value.

Assuming shifts wrap around

These are shifts, not rotates. Bits shifted out are discarded and do not re-enter at the opposite side.

Bitwise operations change patterns under an explicit width, unlike ordinary arithmetic or simple base conversion.

Binary calculator

Addition and multiplication propagate carries and change many bits according to arithmetic. AND, OR, and XOR treat each position independently.

Two’s complement

The converter explains one pattern’s signed meaning. This calculator uses that meaning during signed decimal parsing and arithmetic right shift.

Base converter

Changing base preserves the integer. A bitwise mask or shift can change the integer and can intentionally discard high bits.

IEEE-754 converter

Floating-point bits contain structured sign, exponent, and mantissa fields. Applying arbitrary integer bitwise operations to them changes the encoded float rather than performing floating-point math.

Frequently asked questions

Why does NOT need a bit width?

BigInt has no natural leading boundary, so an unmasked NOT conceptually flips infinitely many leading zeros into ones. The selected width defines which bits belong to the value.

Do signed and unsigned AND produce different bits?

No. AND, OR, and XOR combine raw patterns identically. Signedness changes decimal validation, decimal display, and the behavior of right shift.

What happens when a left shift overflows the width?

Bits that move beyond the selected width are discarded. The result is masked to 8, 16, 32, or 64 bits, matching fixed-width register behavior.

What is the difference between signed and unsigned right shift?

Unsigned right shift inserts zeros. Signed arithmetic right shift repeats the sign bit, so a negative two’s-complement value stays negative as it moves toward -1.

Can I use negative shift counts?

No. A negative count is rejected. Choose the opposite shift operation and use a non-negative count instead.

Are 64-bit operations exact in the browser?

Yes. BigInt is used for operands, masks, shifts, and formatting, avoiding the 32-bit coercion performed by JavaScript’s ordinary number bitwise operators.

Related tools

View all tools

Cookie Preferences

Manage your cookie preferences. Necessary cookies cannot be disabled.

Necessary

Required

Required for language selection, privacy choices, and basic site functionality.

Cookies: NEXT_LOCALE

Analytics

Optional analytics cookies help us understand traffic and improve the website.

Cookies: _ga, _gid, _gat, _clck, _clsk

Advertising

Optional advertising cookies may be used to show relevant ads and measure performance.

Cookies: __gads, _gcl_au, IDE