Saturday, February 05, 2005

ONJava.com: Bitwise Optimization in Java: Bitfields, Bitboards, and Beyond

ONJava.com: Bitwise Optimization in Java: Bitfields, Bitboards, and Beyond: "Bitwise Optimization in Java: Bitfields, Bitboards, and Beyond
by Glen Pepicelli
02/02/2005

Quick quiz: how do you rewrite the statement below, which alternates between two constants, without a conditional?

if (x == a) x= b;
else x= a;

Answer:

x= a ^ b ^ x;
//where x is equal to either a or b"

No comments: