a question about operator

Discussion in 'iOS Programming' started by joonbear, Oct 23, 2010.

  1. macrumors newbie

    Joined:
    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)))
    {
    }
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #3
    And, as such, this code is checking whether 'width' is not a power of 2.

    Code for checking is-a-power-of-2 is commonly a test of the form:
    Code:
    x && !(x & (x-1))
     

Share This Page