Skip to content

Instantly share code, notes, and snippets.

@scottbyrns
Created March 31, 2016 02:49
Show Gist options
  • Save scottbyrns/fae90b35553813814be513bb4c87df73 to your computer and use it in GitHub Desktop.
Save scottbyrns/fae90b35553813814be513bb4c87df73 to your computer and use it in GitHub Desktop.
static func toUInt32Array(slice: ArraySlice<UInt8>) -> Array<UInt32> {
var result = Array<UInt32>()
result.reserveCapacity(16)
for idx in slice.startIndex.stride(to: slice.endIndex, by: sizeof(UInt32)) {
let val1:UInt32 = (UInt32(slice[idx.advanced(by: 3)]) << 24)
let val2:UInt32 = (UInt32(slice[idx.advanced(by: 2)]) << 16)
let val3:UInt32 = (UInt32(slice[idx.advanced(by: 1)]) << 8)
let val4:UInt32 = UInt32(slice[idx])
let val:UInt32 = val1 | val2 | val3 | val4
result.append(val)
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment