Quantcast
Viewing all articles
Browse latest Browse all 1182

Most efficient way of dividing by power of two

I have an array of signed ints, and I would like to divide by 2^n.

I currently use this routine to do it:

int out = in >= 0 ? int >> n : -((int & 0x7FFFFFFF) >> n);

Is there a better way that does not involve a branch?

 

 


Viewing all articles
Browse latest Browse all 1182

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>