Sinisterly
Tutorial Bit masking and shifts - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C)
+--- Thread: Tutorial Bit masking and shifts (/Thread-Tutorial-Bit-masking-and-shifts)

Pages: 1 2 3


RE: Bit masking and shifts - dotcppfile - 09-04-2015

(09-04-2015, 01:14 AM)0xDEAD10CC Wrote: The other trick I use bitshifts for is to efficiently round down to a certain value. Most compilers will use similar tricks in the background if you don't keep your stack properly aligned to optimize for performance between your local variable allocation's through manipulations to the stack pointer directly and any push instructions... But here's an example:

Code:
#include <stdio.h> int main(void) { int x = 42; x &= 0xFFFFFFF0; printf("%d\n", x); return 0; }

This will take away from x the proper value to round the value down to the nearest multiple of 16, in this case 32.

This is kind of smart and neat, I like it, thanks for sharing mate.


RE: Bit masking and shifts - Coca. - 09-10-2015

Thank-you for this tutorial. Although I already knew about bit shifting, I never knew about anything else you stated here. Hopefully I have use for this new knowledge in the future.