View Full Version : a question about operator
joonbear
Oct 23, 2010, 06:10 AM
Hi all, I don't know below operator (&) mean.
Could you help to explain that.
Thanks a lot.
NSUInteger width = 3;
if((width != 1) && (width & (width - 1)))
{
}
robbieduncan
Oct 23, 2010, 07:31 AM
Same as it means in C: bitwise and.
ianray
Oct 23, 2010, 08:14 AM
Same as it means in C: bitwise and.
And, as such, this code is checking whether 'width' is not a power of 2.
if((width != 1) && (width & (width - 1)))
Code for checking is-a-power-of-2 is commonly a test of the form:
x && !(x & (x-1))
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.