我有一個字節數組app0 := []byte("\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00")我想弄清楚如何app0[13:15]用包含300.請幫忙。我嘗試了以下操作,但它甚至無法編譯:app0[13:15] = []byte(300)
2 回答

月關寶盒
TA貢獻1772條經驗 獲得超5個贊
例如,
package main
import "fmt"
func main() {
app0 := []byte("\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x00\x00\x00\x00\x00\x00")
fmt.Println(app0)
app0[13], app0[14] = 300>>8, 300&0xFF
fmt.Println(app0)
}
輸出:
[255 224 0 16 74 70 73 70 0 1 1 1 0 0 0 0 0 0]
[255 224 0 16 74 70 73 70 0 1 1 1 0 1 44 0 0 0]
- 2 回答
- 0 關注
- 220 瀏覽
添加回答
舉報
0/150
提交
取消