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.
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 ]
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.
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:
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
Joined: Jan 30, 2000
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.
Joined: Jul 08, 2000
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 ]