title: How to convert unsigned integer to signed integer without OverflowException
body: <p>I would like to be able to convert a high-valued unsigned-integer (a value that uses the highest-order bit) to a signed-integer.  In this case, I don't care that the value is higher than the maximum value of the signed integer type.  I just want it to convert to whatever the bit-values represent as a signed-integer.  In other words, I would expect it to result in a negative number.  </p>
  
  <p>However, with VB.NET, the <code>CType</code> operation doesn't work that way (or any of the other conversion functions like <code>CShort</code> and<code>CInteger</code>).  When you try to convert an unsigned value that is higher than the desired signed-type's maximum value, it throws an <code>OverflowException</code> rather than returning a negative number.  For instance:</p>
  
  <pre><code>Dim x As UShort = UShort.MaxValue
  Dim y As Short = CShort(x)  ' Throws OverflowException
  </code></pre>
  
  <p>It's worth mentioning, too, that the <code>DirectCast</code> operation cannot be used to cast the value between the signed and unsigned types, since neither type inherits or implements the other.  For instance:</p>
  
  <pre><code>Dim x As UShort = UShort.MaxValue
  Dim y As Short = DirectCast(x, Short)  ' Won't compile: "Value of type 'UShort' cannot be converted to 'Short'
  </code></pre>
  
  <p>I have figured out one way to do what I want, but it seems unnecessarily ugly.  Here's how I got it to work:</p>
  
  <pre><code>Dim x As UShort = UShort.MaxValue
  Dim y As Short = BitConverter.ToInt16(BitConverter.GetBytes(x), 0)  ' y gets set to -1
  </code></pre>
  
  <p>Like I said, that works, but if there's an easier, cleaner way of doing it in VB.NET, I'd love to know what it is.</p>