title: Conversion of Single to two UInt16 values in .NET
body: <p>In the good old days of C, I could cast a float to an int (assuming a 32-bit system), do some bit manipulation (bitwise and, right shift, etc.), and get the upper and lower 16 bit hex representations of the floating point number, which I could then store in two short values. I'm not seeing an easy way of doing this in C#.</p>
  
  <p>System.Convert.ToUInt16 just does a float to int convert (even after I shift right), which leaves a value of 0 if the float is less than 0, which is not the desired effect.</p>
  
  <pre><code>//Useless leaves me with a value of 0
  UIN16 s1 = (UInt16)((System.Convert.ToUInt32(d2) &amp; 0xffff0000) &gt;&gt; 16);   //Capture the high word
  UInt16 s2 = (UInt16)(System.Convert.ToUInt32(d2) &amp; 0xffff);              //Capture the low word
  </code></pre>
  
  <p>A basic cast (UInt32) doesn't work either.</p>