Go uint64 转换 byte,大端字节序列化

时间:2025-03-08 09:17:52
	b := make([]byte, 8)
	.PutUint64(b, uint64(265))

	(b) // [0 0 0 0 0 0 1 9]

	i := int64(.Uint64(b))

	(i) // 265

	a := make([]byte, 8)
	.PutUint64(a, uint64(265))

	(a) // [9 1 0 0 0 0 0 0]

	j := int64(.Uint32(a))

	(j) // 265

	c := make([]byte, 4)
	.PutUint32(c, uint32(265))

	(c) // [9 1 0 0]

	z := int64(.Uint32(c))

	(z) // 265


	buf := (make([]byte, 0))
	(buf, , uint8(35))
	(buf, , uint8(87))
	(buf, , uint8(14))
	(buf, ,  uint8(254))

	(()) // [35 87 14 254]

	b1 := make([]byte, 8)
	.PutUint16(b1, uint16(256))

	(b1) // [1 0 0 0 0 0 0 0]

	.PutUint16(b1, uint16(255))

	(b1) // [0 255 0 0 0 0 0 0]

	buf01 := (make([]byte, 0))
	(buf01, , uint8(35))
	(buf01, , uint8(87))
	(buf01, , uint8(14))

	(()) // [35 87 14]