View Single Post
bitrex
#1
Nov27-09, 02:39 AM
P: 196
If I have the following function:

a = b * c/255

The following function is apparently equivalent using only shifts:

product = b * c;
a = (product + (product>>8) + 1)>>8;

I am having trouble following how this function works. Since an arithmetic right shift is division by a power of 2 right shift 8 would be division by 256...somehow (product + (product>>8) +1) is compensating for the difference between the two but I'm not sure why it's that and not just (product + 1). I'm too thickheaded to see it, any clarification would be appreciated!
Phys.Org News Partner Science news on Phys.org
Suddenly, the sun is eerily quiet: Where did the sunspots go?
'Moral victories' might spare you from losing again
Mammoth and mastodon behavior was less roam, more stay at home