This is more of a thought exercise than anything. Imagine you have been dealt a hand of 5 cards and for this exercise, the order in which they were dealt is significant. If we are using a 52-card deck, there are 52*51*50*49*48 possible ways this can be done. Log_2(52*51*50*49*48) ~ 28.2 bits of entropy.
What I am trying to figure out is a way to convert 28 bits into a unique hand (no other 28-bit sequence can generate the same hand, although in some cases, 2 or more hands might generate the same 28-bit sequence when the process is reversed).
The best I can do so far is pick and remove one of the first 32 cards in the deck (that can be represented with 5 bits), then repeat 4 more times to give 4 more cards and 20 more bits. But that only gives 25 bits. Can anyone think of a process that would give 28 bits, or at least give more than 25?
You can use a mixed radix representation.
hand = card1 + 52 * (card2 + 51 * (card3 + 50 * (card4 + 49 * card5)))
Which is decodable:
card1 = hand % 52
card2 = (hand / 52) % 51
card3 = ((hand / 52) / 51) % 50
card4 = (((hand / 52) / 51) / 50) % 49
card5 = (((hand / 52) / 51) / 50) / 49
(the card numbers are each the index within the "left over" deck, so some further decoding may be required)
The value of hand
is anything between 0 and 51 + 52 * (50 + 51 * (49 + 50 * (48 + 49 * 47))) = 311875199
, so 311875200 different values, exactly what it should be.
That's slightly more than 28 bits of course, limiting the input value to the decoding function to 268435455 or less would "chop off" a specific and predictable set of hands but results in no duplicates.