Newsletter

Programmable Logic DesignLine  >  Blog

Reader query re rounding in binary

I just received an interesting query from a reader with regards to rounding in binary...



Programmable Logic DesignLine

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.

 






 Featured Jobs
T-Mobile seeking Senior Facilities Engineer in Bellevue, WA

Protingent Staffing seeking Quality Engineer in Irvine, CA

Broadcom seeking Principal Packaging Engineer in Irvine, CA

ITT Corporation seeking Systems Engineer in Thousand Oaks, CA

Comverge, Inc. seeking Senior Firmware Engineer in Norcross, GA

More jobs on EETimesCareers
 Sponsor
 CAREER CENTER
Ready to take that job and shove it?
SEARCH JOBS:

 SPONSOR

 RECENT JOB POSTINGS
For more great jobs, career related news, features and services, please visit EETimes' Career Center.