Subject: Re: crack out ur brain for this one

From: [email-masked] (Lance Purple)
Date: Mon, 21 Sep 1998 23:43:05 GMT

> lets start i have a value from 0 to 5 and i would like to fit this
> into 2.5 bits and get it back again later now sense there is no such
> thing as 2.5 bits i need a way to encode 2 values could be any where
> from 0 to 5 into 5 bits?

You can't pack two [0..5] values into five bits, because there
are six possibilities for each value, and 6x6 is more than 32.

But you -can- pack three [0..5] values into eight bits, because
6x6x6 is less than 256.  Pack the values like so:

    Multiply first  value by 36
    Multiply second value by 6,  add
    Multiply third  value by 1,  add

    So [4,2,3] --> (4x36)+(2x6)+3 --> 159,  etc.

    To unpack, divide by 36 to get first value,
               divide remainder by 6 to get second value
               divide remainder of -that- by 1 to get third value

    159 / 36 = 4 remainder 15
 --> 15 /  6 = 2 remainder 3
  --> 3 /  1   3

Hope that helps.

.----------------------------.
| lpurple at netcom dot com  |
'----------------------------'