Convert ushort to string
<p>I have a ushort that consists of two bytes.</p>

<p>15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0</p>

<p>Y = bits 10-0, twos complement mantissa integer.</p>

<p>N = bits 15-11, twos complement integer.</p>

<p>X = Y * 2^N</p>

<p>I need to ouput X as a string.</p>

<p>This is what I have tried:</p>

<pre><code>    private string ConvertLinearToString(ushort data)
    {
        int N;
        int Y;
        int X;

        N = Convert.ToInt16(GetBitRange((byte)data, 0, 5));
        Y = Convert.ToInt16(GetBitRange((byte)data, 6, 11));
        X = Convert.ToInt16(Y * Math.Pow(2, (double)N));

        return Convert.ToString(result);            
    }

    private byte GetBitRange(byte b, int offset, int count)
    {
        return Convert.ToByte((b &gt;&gt; offset) &amp; ((1 &lt;&lt; count) - 1));
    }
</code></pre>

<p>I'm stuck trying to convert the GetBitRange() formula to use ushort and also how to handle the twos complement.</p>
