Assume I have a shuffled deck of cards (52 cards, all normal, no jokers) I'd like to record the order in my computer in such a way that the ordering requires the least bits (I'm not counting look up tables ect as part of the deal, just the ordering itself.
For example, I could record a set of strings in memory:
"eight of clubs", "nine of dimonds"
but that's obviously silly, more sensibly I could give each card an (unsigned) integer and just record that...
17, 9, 51, 33...
which is much better (and I think would be around 6 bits per number times 53 numbers so around 318 bits), but probably still not ideal.. for a start I wouldn't have to record the last card, taking me to 312 bits, and if I know that the penultimate card is one of two choices then I could drop to 306 bits plus one bit that was true if the last card was the highest value of the two remaining cards and false otherwise....
I could do some other flips and tricks, but I also suspect that this is a branch of maths were there is an elegant answer...
There are $52!$ possible ordering of the 52 cards. Each bit can store 2 value, so you need to find the smallest $n$ for which $2^n\geq52!$, $n\geq log_2(52!)$, that is $226$.
The algorithm for rebuild the ordering from the number is the one suggested by Ross Millikan.