title: What is the best way to quantize a float to a byte
body: <p>I have a single-precision float value, and no information about the distribution of the samples from which this value was generated, so I can't apply a sigmoid or perform some kind of normalization. Also, I know the value will always be non-negative. What is the best way to represent this float as a byte?</p>
  
  <p>I've thought of the following:</p>
  
  <p>Interpret the float as a UInt32 (I expect this to maintain relative ordering between numbers, please correct me if I'm wrong) and then scale it to the range of a byte.</p>
  
  <pre><code>UInt32 uVal = BitConverter.ToUInt32(BitConverter.GetBytes(fVal), 0);
  byte bVal = Convert.ToByte(uVal * Byte.MaxValue / UInt32.MaxValue);
  </code></pre>
  
  <p>I'd appreciate your comments and any other suggestions. Thanks!</p>