Hello. I am trying to figure out the best way to convert an array of bytes to IEEE 754 float with big endian.
This is what I have for Integer:
func bytesToInt(Bytes b:[UInt8]) -> Int
{
let bigEndianValue = b.withUnsafeBufferPointer {($0.baseAddress!.withMemoryRebound(to: UInt32.self, capacity: 1) { $0 })}.pointee
let value = UInt32(bigEndian: bigEndianValue)
return Int(value);
}
I am not sure whether something like this is correct:
let bigEndianValue = b.withUnsafeBufferPointer {($0.baseAddress!.withMemoryRebound(to: Float.self, capacity: 1) { $0 })}.pointee
Besides, how to make it a big endian IEEE float?
Thank you so much!