Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is even using bitwise AND.
DSA Go
if num & [1] == 0 { fmt.Println("Even") } else { fmt.Println("Odd") }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 in the bitwise AND operation.
Using the number itself instead of 1 for masking.
✗ Incorrect
Using bitwise AND with 1 checks the least significant bit. If it is 0, the number is even.
2fill in blank
mediumComplete the code to print "Odd" when the number is odd using bitwise operation.
DSA Go
if num & [1] != 0 { fmt.Println("Odd") } else { fmt.Println("Even") }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 in the bitwise AND operation.
Checking for equality to 0 instead of inequality.
✗ Incorrect
If the least significant bit masked by 1 is 1, the number is odd.
3fill in blank
hardFix the error in the code to correctly check if a number is even using bits.
DSA Go
if (num [1] 1) == 0 { fmt.Println("Even") } else { fmt.Println("Odd") }
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' instead of AND '&'.
Using XOR '^' which toggles bits.
✗ Incorrect
The bitwise AND operator '&' is used to check the least significant bit.
4fill in blank
hardFill both blanks to create a function that returns true if a number is even using bits.
DSA Go
func isEven(num int) bool {
return (num [1] 1) [2] 0
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for comparison.
Using '|' instead of '&' for masking.
✗ Incorrect
Use bitwise AND '&' to mask the least significant bit and compare it to 0 with '=='.
5fill in blank
hardFill all three blanks to create a function that returns true if a number is odd using bits.
DSA Go
func isOdd(num int) bool {
return (num [1] 1) [2] 0
}
fmt.Println(isOdd([3]))Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' for odd check.
Using even number for test input.
✗ Incorrect
Use bitwise AND '&' to mask the least significant bit, check if it is not equal to 0 with '!=', and test with number 5.
