Bitwise operations and shifts

后端 未结 3 828
逝去的感伤
逝去的感伤 2020-12-09 12:28

Im having some trouble understanding how and why this code works the way it does. My partner in this assignment finished this part and I cant get ahold of him to find out ho

3条回答
  •  盖世英雄少女心
    2020-12-09 13:05

    c = 33 + ~n;
    

    This calculates how many high order bits are remaining after using n low order bits.

    ((x << c)>>c
    

    This fills the high order bits with the same value as the sign bit of x.

    !(blah ^ x)
    

    This is equivalent to

    blah == x
    

提交回复
热议问题