Using bitwise operations in if statement

bit, c#

Solution

It's because the result of b & 1 is an integer (if b is an integer).

A correct way to do this is (among others):

if ((b & 1) != 0) { ... }

or

`if (Convert.ToBoolean(b & 1)) { ... }`

Problem

Can someone explain why is this not valid? I get "can't convert to int to bool" ``` if (b & 1) ``` also, why can't I do ``` b & 1 ``` in code, is this the correct way of doing this? ``` int b = b & 1 if(b) ``` Thanks!

Original source