Workspace Xor Of Range
0d
Back to questionsDSA Visualizers: 388 Coding Questions

XOR of Range visualizer

Learn XOR of Range with a step-by-step Bit Manipulation visualizer, JavaScript source code and a worked example. Practice bit operations.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 2Execution step
Reference example · JavaScript
Inspect reference input
{
  "l": 3,
  "r": 7
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
l,r
},s)=>{
const f=n=>n%4===0?n:n%4===1?1:n%4===2?n+1:0;
let a=f(l-1),b=f(r);
s("Compute prefix XOR at both boundaries",{
Prefix:[a,b]
});
return a^b
};

Execution canvas

Active Changed
STEP 1

Compute prefix XOR at both boundaries

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Prefix2 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Bit Manipulation · Bit operations

Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.

Example input

{
  "l": 3,
  "r": 7
}

Execution steps

  1. Compute prefix XOR at both boundaries

Computed output

3
JavaScript reference implementation
const solve = ({
  l,r
},s)=>{
  const f=n=>n%4===0?n:n%4===1?1:n%4===2?n+1:0;
  let a=f(l-1),b=f(r);
  s("Compute prefix XOR at both boundaries",{
    Prefix:[a,b]
  });
  return a^b
};

Continue learning

Practice related DSA questions in the same topic.