|
Reader query re rounding in binary
I just received an interesting query from a reader with regards to rounding in binary...
|
|
By
Clive
Maxfield
|


|
Programmable Logic DesignLine
(05/09/2008 11:06 AM EDT)
|

|
|
A few seconds ago as I pen these words, I received the following query from a reader:
Hi Max, I was wondering if there are any clever ways of rounding in binary. Say I have a 24-bit number (0-16777215) and I would like to round to the nearest 1000 (that is values ending in 0-499 round down and 500-999 rounds up).
Of course, I can calculate 1000*int((500+x)/1000) doing a routine divide, truncate, and multiply. However, is there a more "clever" way out there? In a sense, this is a mapping problem. I'm hoping a few simple shifts, AND-ing, OR-ing, and maybe tossing in a few XOR's might do the trick. Any thoughts?
Now, this is the sort of thing I'd love to dabble with (do you remember my paper on Rounding Algorithms 101?). Sad to relate, however, I am absolutely up to my ears in alligators with too much "stuff" to do and nowhere near enough time to do it all in, so do you have any thoughts you'd care to share?
Questions? Comments? Feel free to email me – Clive "Max" Maxfield – at max@techbites.com). And, of course, if you haven't already done so, don't forget to Sign Up for our weekly Programmable Logic DesignLine Newsletter.
|
|
|
|
CAREER CENTER
|
Ready to take that job and shove it?
|
|
SPONSOR
|
|
|
|
RECENT JOB POSTINGS
|
|
|
For more great jobs, career related news, features and services, please visit EETimes' Career Center.
|
|