Converting 3 bytes into signed integer in C#
问题 I'm trying to convert 3 bytes to signed integer (Big-endian) in C#. I've tried to use BitConverter.ToInt32 method, but my problem is what value should have the lats byte. Can anybody suggest me how can I do it in different way? I also need to convert 5 (or 6 or 7) bytes to signed long, is there any general rule how to do it? Thanks in advance for any help. 回答1: As a last resort you could always shift+add yourself: byte b1, b2, b3; int r = b1 << 16 | b2 << 8 | b3; Just swap b1/b2/b3 until you