Algorithm for sbyte?

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Dear All,

Does anyone know the algorithm used to convert to an sbyte like follows? It
is not a straight hex conversion.

sbyte.Parse("B2", System.Globalization.NumberStyles.HexNumber, null);

Any help is appreciated. Thanks and have a great day!

Cheers,
Rich
 
Rich said:
Dear All,

Does anyone know the algorithm used to convert to an sbyte like follows? It
is not a straight hex conversion.

sbyte.Parse("B2", System.Globalization.NumberStyles.HexNumber, null);

It is a straight hex conversion and ends up storing the same binary value in
the byte as it would in an unsigned byte. Its how the binary value is then
interpreted as a number. The top bit being set indicates its a negative
number in signed byte.

The algorithm is called 2's complement. See:-

http://en.wikipedia.org/wiki/Two's_complement
 
Back
Top