I am defining a simple function to do some bitwise operation :
def getBit(num:Int, i:Int):Boolean = (num & (1 << i) != 0)
But I am getting this error :
<console>:7: error: overloaded method value & with alternatives:
(x: Long)Long <and>
(x: Int)Int <and>
(x: Char)Int <and>
(x: Short)Int <and>
(x: Byte)Int
cannot be applied to (Boolean)
def getBit(num:Int, i:Int):Boolean = (num & (1 << i) != 0)
Why I cannot use the &
operator ? How can I solve this error?
The following code should work:
def getBit(num:Int, i:Int):Boolean = ((num & (1 << i)) != 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With