C quick calculation of next multiple of 4?

前端 未结 7 1895
无人共我
无人共我 2020-12-15 05:04

What\'s a fast way to round up an unsigned int to a multiple of 4?

A multiple of 4 has the two least significant bits 0, right? So I could

7条回答
  •  悲哀的现实
    2020-12-15 05:28

    myint = (myint + 4) & 0xffffffc

    This is assuming that by "next multiple of 4" that you are always moving upwards; i.e. 5 -> 8 and 4 -> 8.

提交回复
热议问题