|
|
|
|
|||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
rounding of 4 unsigned char numbers
Hi. I've encountered a problem with rounding which I cannot resolve
elegantly and I has hoping that somebody could help me out. Here's the problem description: We are given 4 numbers a, b, c, and d in the range [0255]. These are 8-bit numbers (unsigned char), but I assume that the solution should exists for any non-negative integer. We are supposed to determine x = x(a, b, c, d) so that the following 2 formulas give identical results: (a + b + c + d + 2) >2 = (((a + c + 1) >1) + ((b + d + 1) >1) + x) >1 This means that the ceiling of quarter sum of 4 numbers should be accomplished in 2 steps. Similar formula should be applied for flooring of quarter sum of 4 numbers: (a + b + c + d) >2 = (((a + c) >1) + ((b + d) >1) + x) >1 Any ideas how can we do this elegantly? It looks like the solution inspects if a, b, c, d are odd or even, plus if they are divisible by 4. Thanks in advance for your help! I'd really appreciate it. Regards, Aleksandar |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > rounding of 4 unsigned char numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|