class CRC32 {
var data = NSData()private static let crcTableLength = Int(UInt8.max) + 1private static var _crcTable = [UInt32](count: crcTableLength, repeatedValue: 0)private static var crcTable: [UInt32] {get {if _crcTable[1] != 0 {return _crcTable}for n in 0..var c = UInt32(n)for _ in 0..<8 {if ((c & 1) != 0) {c = 0xedb88320 ^ (c >> 1)} else {c = c >> 1}}_crcTable[n] = c}return _crcTable}}func getCRC() -> Byte4 {var crc: Byte4 = 0crc = ~crcvar buf = UnsafePointer<UInt8>(data.bytes)let len = data.lengthfor _ in 0..let toBuf = buf.memorybuf += 1let i = Int((crc ^ UInt32(toBuf)) & 0xFF)crc = self.dynamicType.crcTable[i] ^ crc >> 8}return ~crc}}
2016年8月18日 星期四
swift + crc32
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言