Bit Mask usage in the program below from Programming Pearls

后端 未结 2 1326
失恋的感觉
失恋的感觉 2021-01-12 08:18

I started reading \"Programming Pearls\" today and while doing it\'s exercise I came across this question \"How would you implement your own bit vector?\". When I looked at

2条回答
  •  孤街浪徒
    2021-01-12 08:40

    0x20 is 32, so i & 0x1F takes i modulo 32, so that you never shift by 32 bits. This is a safeguard because shifting by anything that isn't strictly less than the size of the type is undefined behaviour.

提交回复
热议问题