douzhenqun1271 2016-06-09 19:23
浏览 1958
已采纳

如何在go中将[] byte数据转换为uint16?

I have the following hex data: 0xB01B; its 45083 as uint16; how do I convert this to uint16 in go?

  • 写回答

1条回答 默认 最新

  • duanmao1872 2016-06-09 19:27
    关注

    Use the encoding/binary package:

    import (
        "encoding/binary"
    )
    
    data := []byte{0xB0, 0x1B}
    val := binary.BigEndian.Uint16(data)
    

    https://play.golang.org/p/wHW8KDgls9

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?