C quick calculation of next multiple of 4?

前端 未结 7 1890
无人共我
无人共我 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:18

    If by "next multiple of 4" you mean the smallest multiple of 4 that is larger than your unsigned int value myint, then this will work:

    (myint | 0x03) + 1;
    

提交回复
热议问题