3 ms·
The only time I find myself using bit manipulations in production code is when I am writing a library that uses an int to represent a set of option flags (where
by gamegoblin 13y ago
The only time I find myself using bit manipulations in production code is when I am writing a library that uses an int to represent a set of option flags (where each bit is a boolean flag). It's pretty common in C libs to define some constants like
int FLAG_1 = 1;
int FLAG_2 = 2;
int FLAG_3 = 4; //These would actually probably be formatted like (1 << N)
...
And then pass in your options to a function like f(... FLAG_1+FLAG_2) so you can have an optional number of flags in a single argument.