tips:java:shiftoperators
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | tips:java:shiftoperators [2009/06/08 12:18] (current) – created erik | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Using shift operator for faster division and multiplication ====== | ||
| + | ** Multiplications ** | ||
| + | |||
| + | <code java> | ||
| + | 12 * 2 = 12 << 1 | ||
| + | 12 * 4 = 12 << 2 | ||
| + | 12 * 8 = 12 << 3 | ||
| + | 12 * 16 | ||
| + | 12 * 32 | ||
| + | 12 * 64 | ||
| + | 12 * 128 = 12 << 7 | ||
| + | 12 * 256 = 12 << 8 | ||
| + | </ | ||
| + | |||
| + | ** Divisions ** | ||
| + | |||
| + | <code java> | ||
| + | 12 / 2 = 12 >> 1 | ||
| + | 12 / 4 = 12 >> 2 | ||
| + | 12 / 8 = 12 >> 3 | ||
| + | 12 / 16 | ||
| + | 12 / 32 | ||
| + | 12 / 64 | ||
| + | 12 / 128 = 12 >> 7 | ||
| + | 12 / 256 = 12 >> 8 | ||
| + | </ | ||
tips/java/shiftoperators.txt · Last modified: by erik
