Monday, May 6, 2013

Bit Twiddling

int conditional(int x, int y, int z) {
    return x ? y : x;
}

int conditional(int x, int y, int z) {
    return ((y&(!x+~0))|(z&~(!x+~0)));
}
WARNING: latter is worse not only because it is unreadable, but it also results the worst assembler code (at least in case of the modern compilers). So be careful by using such shit which you can find in some "clever" books and articles :)

No comments:

Post a Comment