Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the & operator?

In the following code:

Expression<Func<int, bool>> isOdd = i => (i & 1) == 1;

...what is the meaning of (i & 1) == 1?

like image 799
kpax Avatar asked Mar 15 '09 09:03

kpax


1 Answers

Bitwise AND. In this case, checking whether the last bit in i is set. If it is, it must be an odd number since the last bit represents 1 and all other bits represent even numbers.

like image 137
Kent Boogaart Avatar answered Oct 06 '22 16:10

Kent Boogaart