title: Dynamically store numeric values with absolute minimal bits?
body: <p>I am making a game with C#/Unity and want to minimise bandwidth usage.  Ten times a second the server updates clients with changes to unit positions.  The server only sends data if it has changed, and only sends the difference between this and last logged values; which may be positive or negative.  There may be anywhere from zero to a few thousand units in play at any one moment.  </p>
  
  <p>Default data for each unit is one ushort and four float variables (id, x, y, z, direction).  This would be 18 bytes + object (serialization) and datagram bytes.  Right now I'm sending that, but it's simply too much to have a thousand units running about... 18 * 10 * 1000 = 180kb/s. </p>
  
  <p>This can be simplified to whole numbers, as I only care about say two decimal points of precision.  For example: 13.35 - 13.10 = 0.25 ... which we can store as 25.  If a lot of values are going to be much smaller than 255 (a byte) then the best solution will allow us to dynamically store only the bits required plus as little overhead as possible.  The solution will also allow us to send values which are much greater if need be.  </p>
  
  <p>This is useful for other server commands, like applying damage to units, which would require an id and damage value.  The damage value is probably going to be less than 20 most of the time.  </p>
  
  <p>Using C# how can I dynamically store the required data in as few bits as possible for network transport?  </p>