Bitwise Operations

It's fairly convoluted though very efficient to encode lots of pieces of Boolean information into a single integer variable. Normal arithmetic and logical operations on such integer variables become unintuitive since we're not usually concerned with the value of the variables (e.g., 17) but rather with the status of individual bits (say, the first and fifth bits are set, all other bits are unset).

This page presents some bitwise operations I found useful while writing an extremely CPU-intensive ray-tracer. C syntax is used but the techniques can be applied to other languages including Java, often with only minor syntax changes.

Tests

Operations

Other