Convert byte to sbyte - no easy way?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ray Ackley

    Convert byte to sbyte - no easy way?

    I need to convert a byte to an sbyte - and it has to preserve the
    original binary meaning of the 8 bits. For example - a 1111 1111,
    which is interpreted as byte to be 255, should show up in the sbyte as
    -1. The BitConverter class only takes 2 byte arrays or larger, and
    the Convert.ToSByte simply throws an overflow error. Any ideas?

    Thanks,
    Ray Ackley
  • Grant Richins [MS]

    #2
    Re: Convert byte to sbyte - no easy way?

    byte b = 0xFF;
    sbyte sb = unchecked((sbyt e)b);

    --
    --Grant
    This posting is provided "AS IS" with no warranties, and confers no rights.


    Comment

    • Ray Ackley

      #3
      Re: Convert byte to sbyte - no easy way?

      "Grant Richins [MS]" <grantri@online .microsoft.com> wrote in message news:<uqbTEKXpD HA.2588@tk2msft ngp13.phx.gbl>. ..[color=blue]
      > byte b = 0xFF;
      > sbyte sb = unchecked((sbyt e)b);[/color]


      Thanks! That worked great.

      Ray Ackley

      Comment

      Working...