casting - Convert byte to sbyte without changing bits in C# -
i want convert byte sbyte, without changing bits.
byte b = 0x84; sbyte sb = unchecked((sbyte)b); console.writeline("0x" + convert.tostring(b, 16)); console.writeline("0x" + convert.tostring(sb, 16)); the result of be:
0x84 0xff84 i understand result means , why happens. however, cannot seem find out can avoid behaviour. how can copy actual binary value of byte , inside sbyte?
the bit's not changing between b , sb @ all. behavior coming convert.tostring(). there isn't overload of convert.tostring() takes sbyte , base. closest match convert.tostring method (int16, int32). sb being sign extended 16 bits.
Comments
Post a Comment