W
Witless
This is 'supposed' to be a simple problem and shouldn't need too much
time to solve :S
Below is a function that works like this:
int fn(int input)
{
int x=(input/8);
if(x%2)
x= x*8 + 8;
else
x = x*8;
return x;
}
Input -> Output
===========
0..7 -> 0
8..15 -> 16
16..23 -> 16
24..31 -> 32
32..39 -> 32
40..47 -> 48
48..56 -> 48
Problem:
See if you can come up with a more efficient solution that can do it
without any division or multiplication operations.
Hint:
Think about what the numbers look like in binary.
If you have no time to look at it, let me know ASAP.
Thanks for your help in advance.
time to solve :S
Below is a function that works like this:
int fn(int input)
{
int x=(input/8);
if(x%2)
x= x*8 + 8;
else
x = x*8;
return x;
}
Input -> Output
===========
0..7 -> 0
8..15 -> 16
16..23 -> 16
24..31 -> 32
32..39 -> 32
40..47 -> 48
48..56 -> 48
Problem:
See if you can come up with a more efficient solution that can do it
without any division or multiplication operations.
Hint:
Think about what the numbers look like in binary.
If you have no time to look at it, let me know ASAP.
Thanks for your help in advance.