Challenge - 5 Problems
Bitwise Mastery
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 Go code snippet?
DSA Go
package main import "fmt" func main() { a := 12 // binary: 1100 b := 10 // binary: 1010 fmt.Println(a & b) fmt.Println(a | b) }
Attempts:
2 left
💡 Hint
Remember how AND and OR work bit by bit.
✗ Incorrect
AND (&) keeps bits set only if both bits are 1. OR (|) sets bits if either bit is 1.
12 (1100) & 10 (1010) = 8 (1000)
12 (1100) | 10 (1010) = 14 (1110)
❓ Predict Output
intermediateResult of XOR and NOT Operations
What will be printed by this Go program?
DSA Go
package main import "fmt" func main() { x := 5 // binary: 0101 y := 3 // binary: 0011 fmt.Println(x ^ y) fmt.Println(^x) }
Attempts:
2 left
💡 Hint
XOR sets bits where bits differ. NOT flips all bits, resulting in negative number in two's complement.
✗ Incorrect
5 (0101) ^ 3 (0011) = 6 (0110)
^5 flips bits of 5, resulting in -6 in two's complement 32-bit integer.
❓ Predict Output
advancedLeft and Right Shift Effects
What is the output of this Go code?
DSA Go
package main import "fmt" func main() { n := 8 // binary: 1000 fmt.Println(n << 2) fmt.Println(n >> 1) }
Attempts:
2 left
💡 Hint
Left shift multiplies by 2 per shift, right shift divides by 2 per shift.
✗ Incorrect
8 << 2 shifts bits left by 2: 8 * 2^2 = 32
8 >> 1 shifts bits right by 1: 8 / 2 = 4
🧠 Conceptual
advancedUnderstanding Bitwise NOT on Unsigned Integers
In Go, what is the result of applying bitwise NOT (^) to an unsigned 8-bit integer with value 0b00001111 (decimal 15)?
Attempts:
2 left
💡 Hint
NOT flips all bits; for unsigned 8-bit, all 8 bits are flipped.
✗ Incorrect
0b00001111 flipped becomes 0b11110000 which is 240 in decimal.
Since it's unsigned, result is positive.
🔧 Debug
expertIdentify the Error in Bitwise Shift Operation
What error will this Go code produce?
DSA Go
package main import "fmt" func main() { var x int = 1 var y int = 33 fmt.Println(x << y) }
Attempts:
2 left
💡 Hint
Check how Go handles shifts larger than bit size of int.
✗ Incorrect
In Go, shifting by more than or equal to the bit size of the integer type is allowed if the shift count is an untyped constant.
1 << 33 equals 8589934592 (2^33).
