Wednesday, September 07 2005
char *string_value = new char[32];

In computer science we're quite accustomed to using powers of 2 whenever a numerical limit is required. e.g. The string can be 32 characters long, the filename can be 64 characters, while the number of entries in the listbox can number 1024.

These uses seldom require powers of 2 (e.g. while it makes sense for an ASCII string to be multiples of 4 bytes if it's long aligned and you care about that, it could just as efficiently be 28 or 36 characters long), but nonetheless it's ingrained into most developers' minds.

I chuckled seeing the commercial for some overpriced timed-interval air freshener. It allows you to select 9, 18, or 36 minute intervals between sprays. While not exactly compliant (I'll bet that it was originally 8, 16 or 32 minutes, but they added some lag to the minute counter to avoid it seeming computeresque), and in this case I can understand why the microcontroller developer chose powers, the spirit of the power of 2 lives on.

   

Reader Comments

Add Comment

Name *:

Email Address:

(your email address is not displayed)
Website:

Comment *:



About the Author
Dennis Forbes Dennis Forbes is a Toronto-based software architect. While focused primarily on the .NET and SQL Server worlds, Dennis frequently ventures outside of this comfort zone into game development and image processing. He has been published in several industry magazines, has been quoted in the Wall Street Journal and has been interviewed by NPR.

He is a vice president and lead software architect at an innovative New York City hedge fund back-office services firm.

Dennis has been working on solutions for the financial, telecommunications, and power generation markets for over 15 years.





 

Dennis Forbes