Algorithm for sbyte?

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
 
A

Anthony Jones

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top