Complete the code to check if a number is even using bit manipulation.
func isEven(num int) bool {
return num & [1] == 0
}Using num & 1 checks the least significant bit. If it is 0, the number is even.
Complete the code to multiply a number by 2 using bit manipulation.
func multiplyByTwo(num int) int {
return num [1] 1
}Left shifting by 1 bit multiplies the number by 2 efficiently.
Fix the error in the code to divide a number by 4 using bit manipulation.
func divideByFour(num int) int {
return num [1] 2
}Right shifting by 2 bits divides the number by 4 efficiently.
Fill both blanks to toggle the 3rd bit of a number using bit manipulation.
func toggleThirdBit(num int) int {
return num [1] (1 [2] 2)
}Use XOR (^) with 1 shifted left by 2 to toggle the 3rd bit.
Fill all three blanks to create a mask that sets the 1st and 4th bits of a number.
func setBits(num int) int {
mask := (1 [1] 0) [2] (1 [3] 3)
return num | mask
}Shift 1 left by 0 and 3, then OR (|) them to create a mask for 1st and 4th bits.
