J joonbear macrumors newbie Original poster Oct 23, 2010 1 0 Oct 23, 2010 #1 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))) { }
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 Moderator emeritus Jul 24, 2002 25,611 893 Harrogate Oct 23, 2010 #2 Same as it means in C: bitwise and.
I ianray macrumors 6502 Jun 22, 2010 452 0 @ Oct 23, 2010 #3 robbieduncan said: Same as it means in C: bitwise and. Click to expand... And, as such, this code is checking whether 'width' is not a power of 2. joonbear said: Code: if((width != 1) && (width & (width - 1))) Click to expand... Code for checking is-a-power-of-2 is commonly a test of the form: Code: x && !(x & (x-1))
robbieduncan said: Same as it means in C: bitwise and. Click to expand... And, as such, this code is checking whether 'width' is not a power of 2. joonbear said: Code: if((width != 1) && (width & (width - 1))) Click to expand... Code for checking is-a-power-of-2 is commonly a test of the form: Code: x && !(x & (x-1))