you can use binary.BigEndian.Uint16(numBytes)
as this working example code (with comments):
package main
import (
"encoding/binary"
"fmt"
)
func main() {
numBytes := []byte{0xFF, 0x10}
u := binary.BigEndian.Uint16(numBytes)
fmt.Printf("%#X %[1]v\n", u)
}
and see inside binary.BigEndian.Uint16(b []byte):
func (bigEndian) Uint16(b []byte) uint16 {
_ = b[1]
return uint16(b[1]) | uint16(b[0])<<8
}
Hope this helps.
user6169399
source
share