GO語言"encoding/binary"包中"ByteOrder"類型的用法及代碼示例。
ByteOrder 指定如何將字節序列轉換為 16、32 或 64 位無符號整數。
用法:
type ByteOrder interface {
Uint16([]byte) uint16
Uint32([]byte) uint32
Uint64([]byte) uint64
PutUint16([]byte, uint16)
PutUint32([]byte, uint32)
PutUint64([]byte, uint64)
String() string
}
示例(獲取):
package main
import (
"encoding/binary"
"fmt"
)
func main() {
b := []byte{0xe8, 0x03, 0xd0, 0x07}
x1 := binary.LittleEndian.Uint16(b[0:])
x2 := binary.LittleEndian.Uint16(b[2:])
fmt.Printf("%#04x %#04x\n", x1, x2)
}
輸出:
0x03e8 0x07d0
示例(看跌期權):
package main
import (
"encoding/binary"
"fmt"
)
func main() {
b := make([]byte, 4)
binary.LittleEndian.PutUint16(b[0:], 0x03e8)
binary.LittleEndian.PutUint16(b[2:], 0x07d0)
fmt.Printf("% x\n", b)
}
輸出:
e8 03 d0 07
相關用法
- GO Buffer.Bytes用法及代碼示例
- GO Buffer.Read用法及代碼示例
- GO B.RunParallel用法及代碼示例
- GO Buffer.Len用法及代碼示例
- GO Buffer用法及代碼示例
- GO Buffer.Next用法及代碼示例
- GO Buffer.ReadByte用法及代碼示例
- GO B.ReportMetric用法及代碼示例
- GO Base用法及代碼示例
- GO Buffer.Cap用法及代碼示例
- GO Builder用法及代碼示例
- GO Buffer.Grow用法及代碼示例
- GO BinaryOp用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 ByteOrder。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。