Skip to content

Instantly share code, notes, and snippets.

@19h
Created July 2, 2013 14:47
Show Gist options
  • Select an option

  • Save 19h/5909914 to your computer and use it in GitHub Desktop.

Select an option

Save 19h/5909914 to your computer and use it in GitHub Desktop.
General Optimizations
Operation => Optimized Operation.
x * 10 => (((x << 2) + x) << 1)
x * 100 => ((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1)
x * 1000 =>(((((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1) << 2) + ((((((x << 2) + x) << 1) << 2) + (((x << 2) + x) << 1)) << 1)) << 1)
x * 2 => x << 1
x * 4 => x << 2
x * 8 => x << 3
x * 16 => x << 4
x * 32 => x << 5
x / 2 => x >> 1
x / 4 => x >> 2
x / 8 => x >> 3
x / 16 => x >> 4
x / 32 => x >> 5
x % 4 => i & 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment