Im making a online game, and as in many online games i will need loads of data being transfered via internet, so i need to be able to compress data efficiently.
For instance i want to send from my client to the server my character coordinates.
Edit: yeah bad example, let me change the values...
X coordinate(say -32 to 32).(65 diferent possible values) Y coordinate(-32 to 32).(65 diferent possible values) Z coordinate(-16 to 16).(33 diferent possible values)
i know that X was stored before Y that was stored before Z on the byte array before sending.
i know in the server that X cannot be lower than -31 nor higher than 32, the same for the other values.
65*65*33 = 139.425 diferent possible combinations of values for the 3 numbers = 17 bits.
7 + 7 + 5 = 19 bits.
so if i were to store X in the first 7 bits, then Y in the next 7 bits and then Z in the next 5 bits it would take 19 bits and i would be able to read them back in the other side with ease, but since all the posible combinations of values those 3 numbers can take would only take 17 bits to store i feel like im losing space here. Is there a good way to compress those 3 numbers using less than 19 bits?
of course 19 bits and 17 bits both need 3 bytes, but if it were 17 bits and 15 bits it would make a huge diference.