golang float32/64与[]byte互转
来源:互联网 发布:linux iso 写入u盘 编辑:程序博客网 时间:2024/05/16 17:01
网络协议开发中经常需要将int、float、bool等转为二进制数据,float32、64 与[]byte处理:
import ( "encoding/binary" "math")func Float32ToByte(float float32) []byte { bits := math.Float32bits(float) bytes := make([]byte, 4) binary.LittleEndian.PutUint32(bytes, bits) return bytes}func ByteToFloat32(bytes []byte) float32 { bits := binary.LittleEndian.Uint32(bytes) return math.Float32frombits(bits)}func Float64ToByte(float float64) []byte { bits := math.Float64bits(float) bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, bits) return bytes}func ByteToFloat64(bytes []byte) float64 { bits := binary.LittleEndian.Uint64(bytes) return math.Float64frombits(bits)}
0 0
- golang float32/64与[]byte互转
- golang float32/64与[]byte互转
- golang(Go语言) byte/[]byte 与 二进制形式字符串 互转
- golang uint8、int8与byte的区别
- Golang黑科技之——string与[]byte转换
- golang []byte转string
- int 与 byte 互转
- BufferedImage与byte[]互转
- 文件与byte[]互转
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转 .
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转
- BufferedImage与byte[]互转
- String与byte[]互转
- Linux运行时IO设备电源管理框架---PM
- iOS让软键盘消失的简单方法
- 最全面的65条最常用正则表达式
- Spring Bean的生命周期
- Nginx配置文件(nginx.conf)配置详解
- golang float32/64与[]byte互转
- c++ 使用libcurl 发送http get/post请求
- 单点登录(SSO)实现逻辑分享
- 欧拉函数的一个性质及其证明
- sqlmap用户手册
- 可变字典(NSMutableDictionary)简介
- MySQL各个版本的区别
- Java 5种字符串拼接方式性能比较。
- requestAnimationFrame,Web中写动画的另一种选择