Jerry
unread,Nov 9, 2012, 4:59:36 AM11/9/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
I got a file containing a 4 bytes float, which is previously generated by C program via fwrite(), and I know the byte-order is Big Endian.
now i want to read the float into memory as type float32, how can I do this?
My current solution is as follows:
package main
import (
"os"
"encoding/binary"
"math"
"fmt"
)
func main() {
fd, err := os.Open("file_containing_a_4bytes_float")
if err != nil {
return
}
b := make([]byte, 4)
fd.Read(b)
f := math.Float32frombits(binary.BigEndian.Uint32(b)) // I believe this is not idiomatic
fmt.Println(f)
}
I believe this is not the idiomatic way to read a float32 from a file, any hint on how to do this?
Regards,
Jiayu