duanhao7786 2017-07-09 21:01
浏览 113
已采纳

在go中将3个字节转换为int?

I know how to use "encoding/binary" to convert 4 bytes to an int, etc.

What is the most efficient way to convert just 3 bytes to an int?

  • 写回答

1条回答 默认 最新

  • dshm8998473 2017-07-09 21:16
    关注

    Little endian:

    n := int(uint(b[0]) | uint(b[1])<<8 | uint(b[2])<<16))
    

    Big endian:

    n := int(uint(b[2]) | uint(b[1])<<8 | uint(b[0])<<16))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?