golang float32/64与[]byte互转
来源:互联网 发布:免费网络短信发送平台 编辑:程序博客网 时间:2024/06/06 03:34
网络协议开发中经常需要将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[]互转
- TensorFlow下网络模型的存储与加载
- CSDN去广告小脚本
- 【第三周项目1】 顺序表的基本运算
- Codeforces846D(二分+树状数组)
- 理解maven的核心概念
- golang float32/64与[]byte互转
- nginx学习随笔--client_body_temp_path
- Linux下Socket简单通信
- C++容器-3关联容器map、set
- 笔试题:求第n个丑数
- C语言实现cordic算法求sin和cos值
- java通过jedis连接redis
- 图解原型链
- 多线程同步的五种方法