c++'s shift operator >> and <<

the use of the c++'s shift operator << and the >>

  • where we can use?
    -> we can use it to represent the 1k, 1M, or the 1G, that is very useful;
    -> we can use it to the represent the power(2, n), for example, 2^2 is the 1 << 2;

  • what does it means for the: 1 << 1 and the 1 << 31?
    -> 1 << 1: means that 0....01 left shift 1 bit, that is the 0...10, that is the 2;
    -> 1 << 31: means the 0....01 left shift 31 bit, that is the 1...0, that is the 2^31;
    -> from the above, we can make the conclusion that, for the 1 << n: means the 2^n;
    -> for the k << n, that is the $k*2^{n}$

posted @ 2022-10-18 21:12  gj&sq  阅读(41)  评论(0)    收藏  举报