Created
March 31, 2016 02:49
-
-
Save scottbyrns/fae90b35553813814be513bb4c87df73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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