- Joined
- May 17, 2007
- Messages
- 2,469
- Reaction score
- 681
Can bytes have a negative value when sent via a socket?
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)