How do you convert 3 bytes into a 24 bit number in C#?

后端 未结 5 982
我在风中等你
我在风中等你 2020-12-10 19:15

I have an array of bytes that I read from a header section of a message. These bytes contain the length of the message. There never are more than 3 bytes and they are ordere

5条回答
  •  鱼传尺愫
    2020-12-10 19:45

    Something like this should work:

    data[0] + 256*data[1] + 256*256*data[2]
    

    Your compiler should optimize that to the 'right' bit twiddling operations.

提交回复
热议问题