Cool bitwise trick page
-
Bit hacks[^] For example: Round up to the next highest power of 2:
unsigned int v; // compute the next highest power of 2 of 32-bit v
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;This makes my previous code soooo lame (Math.Pow(2,Math.Log(v,2)+1)) or sth like this).
Greetings - Jacek
-
Bit hacks[^] For example: Round up to the next highest power of 2:
unsigned int v; // compute the next highest power of 2 of 32-bit v
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;This makes my previous code soooo lame (Math.Pow(2,Math.Log(v,2)+1)) or sth like this).
Greetings - Jacek
It's a good reference, but on the average day (ok no, but often enough) I also need one of the various mirrors/rotates on a 64bit int as 8x8 matrix (that site is also a good reference).
-
It's a good reference, but on the average day (ok no, but often enough) I also need one of the various mirrors/rotates on a 64bit int as 8x8 matrix (that site is also a good reference).
+5,, Thanks for the link