bit-shifting by an integer value

前端 未结 2 1949
太阳男子
太阳男子 2021-01-21 12:42

This code is for a cache simulator project - I am trying to extract certain bits from a memory address. When I attempt to use int variables to do the bit shifting, I end up with

2条回答
  •  日久生厌
    2021-01-21 13:47

    All integer literal values are int type, unless you specify a prefix such as e.g. 1ULL.

    That means that 1<<33 shifts a 32-bit signed value 33 steps. You need to do 1ULL << 33.

提交回复
热议问题