Challenge - 5 Problems
Bitwise Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Bitwise AND and OR Operations
What is the output of the following TypeScript code?
const a = 5; // binary 0101 const b = 3; // binary 0011 const andResult = a & b; const orResult = a | b; console.log(andResult, orResult);
DSA Typescript
const a = 5; // binary 0101 const b = 3; // binary 0011 const andResult = a & b; const orResult = a | b; console.log(andResult, orResult);
Attempts:
2 left
💡 Hint
Remember how AND and OR work bit by bit.
✗ Incorrect
AND compares each bit: 0101 & 0011 = 0001 (1). OR compares each bit: 0101 | 0011 = 0111 (7).
❓ Predict Output
intermediateResult of XOR and NOT Operations
What will be printed by this TypeScript code?
const x = 12; // binary 1100 const y = 10; // binary 1010 const xorResult = x ^ y; const notResult = ~x; console.log(xorResult, notResult);
DSA Typescript
const x = 12; // binary 1100 const y = 10; // binary 1010 const xorResult = x ^ y; const notResult = ~x; console.log(xorResult, notResult);
Attempts:
2 left
💡 Hint
XOR is 1 when bits differ. NOT flips all bits and changes sign.
✗ Incorrect
XOR: 1100 ^ 1010 = 0110 (6). NOT 12 (00001100) flips bits to 11110011 which is -13 in two's complement.
❓ Predict Output
advancedLeft and Right Shift Effects
What is the output of this TypeScript code?
let num = 7; // binary 00000111 const leftShift = num << 2; const rightShift = num >> 1; console.log(leftShift, rightShift);
DSA Typescript
let num = 7; // binary 00000111 const leftShift = num << 2; const rightShift = num >> 1; console.log(leftShift, rightShift);
Attempts:
2 left
💡 Hint
Left shift multiplies by 2 twice, right shift divides by 2 once.
✗ Incorrect
7 << 2 = 7 * 4 = 28. 7 >> 1 = floor(7 / 2) = 3.
🔧 Debug
advancedIdentify the Error in Bitwise NOT Usage
What error or unexpected behavior occurs when running this TypeScript code?
const val = 0; const result = ~val; console.log(result);
DSA Typescript
const val = 0;
const result = ~val;
console.log(result);Attempts:
2 left
💡 Hint
Think about how NOT works on binary numbers and two's complement.
✗ Incorrect
NOT flips all bits. For 0 (all zeros), ~0 is all ones which is -1 in two's complement.
🧠 Conceptual
expertEffect of Right Shift on Negative Numbers
In TypeScript, what is the output of this code?
const neg = -8; // binary representation in two's complement const shifted = neg >> 2; console.log(shifted);
DSA Typescript
const neg = -8; // binary representation in two's complement const shifted = neg >> 2; console.log(shifted);
Attempts:
2 left
💡 Hint
Right shift on negative numbers keeps the sign bit (arithmetic shift).
✗ Incorrect
Right shifting -8 (11111000) by 2 keeps sign bits, resulting in -2.
