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
Security CTO to detail Android Fake ID flaw at Black Hat
Huge waves measured for first time in Arctic Ocean
Mysterious molecules in space