4 ms·
The abs() trick works for storing one flag bit. But you can store more than one bit if you shift by N bits left and use the LSBs as flag/boolean bits (then circ
by jmiserez 11y ago
The abs() trick works for storing one flag bit. But you can store more than one bit if you shift by N bits left and use the LSBs as flag/boolean bits (then circular shift right + mask when reading). You reduce the range of the local variable by a factor of 2 for every bit stored though (same as the abs trick). Tagged pointers use this method, but instead of shifting one can simply set/clear the bits due to implied alignment:
https://en.wikipedia.org/wiki/Tagged_pointer https://en.wikipedia.org/wiki/Tagged_pointer
- prmichaelsen 11y agoInteresting! It never ceases to amaze me what tricks one can pull off with bit manipulation! Thanks for reading!