[General] negative byte value?
Can bytes have a negative value when sent via a socket?
Re: [General] negative byte value?
If Im not wrong, yes they can:
When you use a signed variable, it will use one way of interpreting bits, if you use unsigned, it uses another, i.e. you can send a negative value, then the receiver needs to get it as signed, if it gets as unsigned, it will be a huge value.
Re: [General] negative byte value?
Quote:
Originally Posted by
BBim
If Im not wrong, yes they can:
When you use a signed variable, it will use one way of interpreting bits, if you use unsigned, it uses another, i.e. you can send a negative value, then the receiver needs to get it as signed, if it gets as unsigned, it will be a huge value.
Don't know about the other languages, but in C#, any sending method via a socket requires the use of unsigned byte(s) (0-255), so i wasn't sure if you can send a negative byte value
Java uses a signed byte, but most of the time, people use the binary "&" operator to get the 0-255 range (0xff)
Re: [General] negative byte value?
Quote:
Originally Posted by
TheAJ
Don't know about the other languages, but in C#, any sending method via a socket requires the use of unsigned byte(s) (0-255), so i wasn't sure if you can send a negative byte value
Java uses a signed byte, but most of the time, people use the binary "&" operator to get the 0-255 range (0xff)
Im not sure how C# handles that, but Im pretty sure you can cast the signed byte to unsigned, then send, when the other receive it, receive as unsigned and cast to signed, then it would be exactly the same of when it was sent.