Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save massimilianochiodi/be64a55146a568b70532ad19bbb4c8d6 to your computer and use it in GitHub Desktop.
Save massimilianochiodi/be64a55146a568b70532ad19bbb4c8d6 to your computer and use it in GitHub Desktop.
Get unsigned integer32 from 4 byte array
fileprivate func getUnsignedInteger32(bigEndian: Bool = true, data: Data) -> UInt32 {
let returnvalue: UInt32 = data.withUnsafeBytes { rawPointer in
rawPointer.bindMemory(to: UInt32.self).baseAddress!.pointee
}
return bigEndian ? returnvalue.bigEndian : returnvalue.littleEndian
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment