[英]How do you convert array of byte to array of float64
I am searching to convert an array of byte ([]byte) to array of float64 ([]float64) but I didn't have any clues to do it.我正在寻找将字节数组([]byte)转换为 float64 数组([]float64),但我没有任何线索可以做到这一点。
I read data from rtlsdr package ( https://pkg.go.dev/github.com/jpoirier/gortlsdr ) and would pass it to Pwelch algorithm ( https://pkg.go.dev/github.com/mjibson/go-dsp/spectral ) I read data from rtlsdr package ( https://pkg.go.dev/github.com/jpoirier/gortlsdr ) and would pass it to Pwelch algorithm ( https://pkg.go.dev/github.com/mjibson/go -dsp/光谱)
Is it possible to convert large array of byte to float64?是否可以将大字节数组转换为 float64?
(+ another question: did you think that possible to convert Pwelch function to work with uint8?) (+ 另一个问题:您认为可以将 Pwelch function 转换为与 uint8 一起使用吗?)
Thank you so much, pefr非常感谢,pefr
byte
/ uint8
has 8 bits, float64
has 64. You can convert [8]byte
to float64
like this: byte
/ uint8
有 8 位, float64
有 64 位。您可以像这样将[8]byte
转换为float64
:
package main
import (
"encoding/binary"
"fmt"
"math"
)
main()
{
in := 1.
// Convert float64 to [8]byte
var bytes [8]byte
binary.LittleEndian.PutUint64(bytes[:], math.Float64bits(in))
// Convert [8]byte to float64
out := math.Float64frombits(binary.LittleEndian.Uint64(bytes[:]))
fmt.Println(out)
}
You may want to chose binary.BigEndian
instead.您可能想选择binary.BigEndian
。
Is that what you are looking for?那是你要找的吗? Or do you want to convert an array of byte
with length 8n to an array of float64
with length n?还是要将长度为 8n 的byte
数组转换为长度为 n 的float64
数组? Feel free to comment:-)随意评论:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.