Bit Manipulation

从右起第一个为1的bit: a &-a;   

example:

a = 4 //1100

-a= -4 //0011+1 = 0100

a&-a = 0100

 

-----------------------

 

 

 

------------------------

作用于bit的逻辑运算符:

&   // and

|  // or

^   // xor

~   // not

作用于变量时,bitwise

5&3=1 // 101&11=1

 

------------------------

<< //左移

>> // 右移

左移右移不会改变变量本身的值

int a=5; //101

cout<<(a<<1)<<endl; //10

cout<<a<<endl; //5

    

posted @ 2016-01-09 10:29  飞飞喵  阅读(187)  评论(0编辑  收藏  举报