Meaning of bitwise and(&) of a positive and negative number?

后端 未结 8 1863
名媛妹妹
名媛妹妹 2021-02-04 11:59

Can anyone help what n&-n means?? And what is the significance of it.

8条回答
  •  礼貌的吻别
    2021-02-04 12:38

    As @aestrivex has mentioned, it is a way of writing 1.Even i encountered this

    for (int y = x; y > 0; y -= y & -y)
    

    and it just means y=y-1 because
    7&(-7) is x00000111 & x11111001 = x00000001 = 1

提交回复
热议问题