This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Memory Saver - 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Memory Saver - 1" Watch "Memory Saver - 1" New topic
Author

Memory Saver - 1

Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Represent a date in the format mmddyyyy in the least amount of memory possible. Solution need not be Java specific, you can use C notations if you want.
[ June 03, 2003: Message edited by: Sriraj Rajaram ]

Commentary From the Sidelines of history
Damian Ryan
Ranch Hand

Joined: May 09, 2003
Posts: 117
The information could be encoded into 23 bits:
4 bits for the month (0-14 covers 1-12 or 0-11)
5 bits for the date (0-31 covers 1-31 or 0-30)
14 bits for the year (0-16383 covers 1-9999)
So the information could be stored in a single int:
000000000mmmmdddddyyyyyyyyyyyyyy
Assuming month, date amd year are int values that have been validated as being in range, you should be able to get the stored value by:

to get month, date and year back from the value:

I haven't tried any of that for real, so I might be completely wrong


Always proofread carefully to see if you any words out.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It's possible to do it in 22 bits - or less if we restrict the year range to something more realistic. E.g. by limiting years to a span of 178 years, we can get it down to 16 bits, fitting nicely in a short. Here's a 22-bit solution for years 1-9999:


"I'm not back." - Bill Harding, Twister
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
E.g. by limiting years to a span of 178 years
Are you trying to start another Y2K incident?


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Hey, Sriraj wants to minimize the memory, I am just offering options. If that means he will have to employ me years from now to sort out the mess made by all the applications he builds on this solution, well, I'm not complaining.
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
All your answers were correct. I think 178 years is more than enough for anyone (trying to act like Bill Gates.. )
Given the situation in the IT industry, I definetly would love another Y2K problem. So that demand goes up again. Anyway that thought belongs in a different forum.
[ June 04, 2003: Message edited by: Sriraj Rajaram ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory Saver - 1
 
Similar Threads
How To Sponsor H1 Candidates
WA #1.....word association
How to detect memory leak ?
how many data can be set in context ,session ,and request ? 500M is OK ?Thank you!
Excel 2007 with JasperReport