0

oxfc is negative but I have it as a byte and its value is 252, is there any way to convert it to signed byte or int?

I found this method:

(BitConverter.ToInt16(new byte[2] { 0, 0xfc }, 0) / 256).ToString() 

But is there any better way?

1 Answer 1

11

You can simply cast it:

byte b = 0xfc; sbyte s = unchecked((sbyte)b); 
Sign up to request clarification or add additional context in comments.

4 Comments

He said "oxfc is negative" so I don't think a negative value can be casted to a byte. Let me know if I'm wrong.
@Transcendent: He says he has 0xFC already in a byte (its value is 252) and wants it interpreted in two's complement (-4) and saved to a signed varianle.
So that's a positive value in that case, I don't understand why he mentioned that 0xfc is a negative value.
@Transcendent: It is negative according to a two's complement interpretation. (actually, also according to one's complement and signed-magnitude)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.