Bit Hack - Round off to multiple of 8

前端 未结 7 2083
情歌与酒
情歌与酒 2021-01-31 12:42

can anyone please explain how this works (asz + 7) & ~7; It rounds off asz to the next higher multiple of 8.

It is easy to see that ~7 produces 11111000 (8bit repre

7条回答
  •  执念已碎
    2021-01-31 12:54

    The +7 isn't to produce an exact multiple of 8, it's to make sure you get the next highest multiple of eight.

    edit: Beaten by 16 seconds and several orders of quality. Oh well, back to lurking.

提交回复
热议问题