How would i go about turning a float32 into 4 bytes?
And then turn 4 bytes back into a float32?
--
Aram Hăvărneanu
That does not convert between a 32 bit native float and 4 bytes. It converts to the specified byte order. You can use unsafe to convert from 4 bytes in native byte order to a float 32.
On Thu, Feb 23, 2012 at 12:52 PM, Jan Mercl <jan.m...@nic.cz> wrote:On Thursday, February 23, 2012 8:12:12 PM UTC+1, Tai Trinh wrote:
How would i go about turning a float32 into 4 bytes?And then turn 4 bytes back into a float32?
9 // Float32bits returns the IEEE 754 binary representation of f. 10 func Float32bits(f float32) uint32 { return *(*uint32)(unsafe.Pointer(&f)) } 11 12 // Float32frombits returns the floating point number corresponding 13 // to the IEEE 754 binary representation b. 14 func Float32frombits(b uint32) float32 { return *(*float32)(unsafe.Pointer(&b)) }