Bitwise shift operation on a 128-bit number

后端 未结 5 694
礼貌的吻别
礼貌的吻别 2020-12-11 05:43

Lets say that I have an array of 4 32-bit integers which I use to store the 128-bit number

How can I perform left and right shift on this 128-bit number?

Tha

5条回答
  •  粉色の甜心
    2020-12-11 06:46

    First, if you're shifting by n bits and n is greater than or equal to 32, divide by 32 and shift whole integers. This should be trivial. Now you're left with a remaining shift count from 0 to 31. If it's zero, return early, you're done.

    For each integer you'll need to shift by the remaining n, then shift the adjacent integer by the same amount and combine the valid bits from each.

提交回复
热议问题