简体   繁体   中英

What does this c code trying to do

What does the following c code trying to do. I am not sure what does it calculate the value of width to

(width+31)&~31

Thank you.

It is rounding up to the next multiple of 32. It only works because 32 is a power of 2.

The bit pattern for  31 is ...000000000011111
The bit pattern for ~31 is ...111111111100000

When you and ~31 with any positive integer, you get a multiple of 32 (five low order bits are all zeroes).

它将width向上舍入为32的倍数。

它重置(关闭)“宽度”的最后5位,这导致width%32 = 0,即32的宽度倍数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM