Why GetBytes returns array of two elements instead of array of one element, although storage of sbyte takes only 1 byte.
byte[] byteArray = BitConverter.GetBytes((sbyte)127)
GetBytes does not have an overload that takes an sbyte, so your sbyte is being implicitly converted to short and you call GetBytes(short), which returns two bytes.
You should simply cast your sbyte to a byte with unchecked conversion.
sbyte s = 127;
byte[] byteArray = new[] { (byte)s };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With