July 2002
Intermediate to advanced
320 pages
8h 15m
English
Rounding an unsigned integer x down to, for example, the next smaller multiple of 8, is trivial: x & −8 does it. An alternative is
These work for signed integers as well, provided “round down” means to round in the negative direction (e.g., (−37) & (−8) = −40).
Rounding up is almost as easy. For example, an unsigned integer x can be rounded up to the next greater multiple of 8 with either of
![]()
These expressions are correct for signed integers as well, provided “round up” means to round in ...
Read now
Unlock full access