Workspace Check Ith Bit
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Check Ith Bit visualizer

Learn Check Ith Bit 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 / 3Execution step
Reference example · JavaScript
Inspect reference input
{
  "x": 13,
  "i": 2,
  "op": "check"
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
x,i,op
},s)=>{
let mask=1<<i,v=op==="check"?(x>>i)&1:op==="set"?x|mask:op==="clear"?x&~mask:x^mask;
s("Create bit mask",{
Input:[...x.toString(2)],Mask:[...mask.toString(2).padStart(4,"0")]
});
s("Apply "+op,{
Result:[...v.toString(2)]
});
return v
};

Execution canvas

Active Changed
STEP 1

Create bit mask

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

Input4 items
Mask4 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

{
  "x": 13,
  "i": 2,
  "op": "check"
}

Execution steps

  1. Create bit mask
  2. Apply check

Computed output

1
JavaScript reference implementation
const solve = ({
  x,i,op
},s)=>{
  let mask=1<<i,v=op==="check"?(x>>i)&1:op==="set"?x|mask:op==="clear"?x&~mask:x^mask;
  s("Create bit mask",{
    Input:[...x.toString(2)],Mask:[...mask.toString(2).padStart(4,"0")]
  });
  s("Apply "+op,{
    Result:[...v.toString(2)]
  });
  return v
};

Continue learning

Practice related DSA questions in the same topic.