Premium experiment • bit-column reasoning

COMPUTER SCIENCE & TECHNOLOGY • COMPUTING

Binary & Bitwise Explorer

Explore binary representation and bitwise AND, OR, XOR and NOT operations.

● INTERACTIVEBinary & Bitwise Explorer
Result
Binary result
A in binary
B in binary

Reasoning inspector

live model state
A in binary—
B in binary—
Operation—
Result decimal—
Result binary—
1-bits in A—
1-bits in B—
1-bits in result—
Word width—

Explore binary operations

Move decimal values and see how their bit patterns combine one bit position at a time.

LEARN WITH THE SIMULATION

Understand Binary & Bitwise Explorer by experimenting.

START HERE

Bitwise operations treat integers as fixed-width patterns and operate independently on corresponding bit positions. That makes them ideal for masks, packed flags and low-level data manipulation. This eight-bit laboratory keeps decimal and binary views synchronized and adds population counts—the number of one-bits—so AND, OR, XOR and NOT can be understood as transformations of sets of active bit positions rather than mysterious decimal results.

BUILD THE IDEA

What you should understand first

  • Convert an unsigned byte between decimal and eight-bit binary representation.
  • Apply AND, OR, XOR and width-limited NOT one bit column at a time.
  • Use AND masks to preserve selected positions and clear others.
  • Interpret XOR as a difference/toggle mask and population count as the number of active bits.

TRY IT YOURSELF

Why does AND with 00001111 preserve exactly the lower nibble of any byte?

  1. Choose any A value and set B=15, whose eight-bit representation is 00001111.
  2. Select AND and compare every result bit with the corresponding A and B bits.
  3. Change the upper four bits of A without changing its lower four and observe the result.
  4. Switch to XOR using the same B and identify which positions are toggled instead of preserved.
Read the visual:

AND can output one only where the mask contains one, so zero mask bits force corresponding result bits to zero. XOR with a one flips a bit, while XOR with zero leaves it unchanged.

WHY IT WORKS 01

Bitwise operations run the same Boolean gate independently in each column

An eight-bit AND is eight independent AND-gate evaluations: bit 7 of A with bit 7 of B, bit 6 with bit 6 and so on. No carry moves between columns as it does in arithmetic addition. The binary result therefore exposes the operation directly in a way the decimal result can obscure.

WHY IT WORKS 02

Masks let code select a subset of bit positions

An AND mask containing ones in desired positions preserves those A bits and clears positions where the mask has zero. OR can force selected positions on, while XOR toggles selected positions. These three patterns—keep/clear, force/set and toggle—are core idioms in low-level programming.

WHY IT WORKS 03

Population count summarizes how many flags are active

The population count, often called popcount or Hamming weight, is the number of one-bits in a word. Comparing the popcount of A, B and the result helps describe what an operation did globally while the full binary strings still show exactly which positions changed.

DO NOT MIX THESE UP

Common misconception

Bitwise NOT depends on word width; this simulator uses eight bits, so NOT A means (~A) AND 11111111₂. XOR is not exponentiation, and binary notation is not a different numerical quantity—it is another representation of the same integer.

PRACTICE CHALLENGE

Can you design a mask that preserves, sets or toggles only the bit positions you intend?

  • Choose an A value and identify the bit positions you want to affect.
  • Construct B mentally for an AND, OR or XOR operation.
  • Adjust B until the binary result matches your prediction.
  • Use the result popcount and bit pattern to explain which positions changed and which stayed untouched.
Reveal the reasoning

For AND, put ones in B where A should be allowed through and zeros where it should be cleared. For OR, put ones where the result must be forced on. For XOR, put ones where A should toggle. The operation is applied independently at every bit position.

MODEL BOUNDARIES

What this simulation assumes

Every simulation simplifies reality or a mathematical system. These are the assumptions and limits to keep in mind while interpreting the results.

Model assumptions

  • Values are unsigned integers within the selected fixed bit width.
  • Bitwise operations use ordinary binary AND, OR, XOR and masked NOT behavior.
  • Overflow beyond the selected width is excluded or masked by the model.

Model limitations

  • Signed integer encodings, floating-point formats and arbitrary-width arithmetic are not represented.
  • Real programming languages may differ in coercion and integer-width rules.

CONNECT IT

Where this matters

  • Permission and feature flags
  • Color and pixel channels
  • Embedded registers and protocols
  • Checksums, toggles and compact state storage

WORDS THAT MATTER

Key vocabulary

Bit
Binary digit with value zero or one.
Mask
Bit pattern used to select or modify specific bit positions.
Population count
Number of one-bits in a binary word.
Nibble
Group of four bits; an eight-bit byte contains two nibbles.
Bitwise NOT
Width-limited operation that flips every bit in the selected word.