Saeros
Destroyer of Worlds
This is probably a simple math problem, but i suck at math
.
Given number x, where x is between 0 and 255, I need to find the nearest multiple of y, where y is a power of 2 between 0 and 128, to x.
I'm not sure if i described that properly, so I'll give an example. Suppose I have number 87, and i need to find the nearest multiple of 16 thereto. In this case, the answer would be 80; 87/16=5.4375 and (5.4375-0.4375)*16=80.
Does anybody know of any way by which to do this calculation really fast? I only have a couple of seconds to figure it out, and i won't have access to a calculator
.
Bonus points awarded to anyone who can guess what this is for

Given number x, where x is between 0 and 255, I need to find the nearest multiple of y, where y is a power of 2 between 0 and 128, to x.
I'm not sure if i described that properly, so I'll give an example. Suppose I have number 87, and i need to find the nearest multiple of 16 thereto. In this case, the answer would be 80; 87/16=5.4375 and (5.4375-0.4375)*16=80.
Does anybody know of any way by which to do this calculation really fast? I only have a couple of seconds to figure it out, and i won't have access to a calculator

Bonus points awarded to anyone who can guess what this is for
