Avatar
@swift-5.1.5 import Foundation let array: [UInt8] = [ 0x10, 0x20, 0x30, 0x40, 0x11, 0x21, 0x31, 0x41, 0x99] let a = array.withUnsafeBufferPointer { (buf) -> Int in buf.baseAddress!.withMemoryRebound(to: Int.self, capacity: 1) { (ip) in ip.pointee } } print(String(format: "%016llx", a), a == Int(bitPattern: 0x4131211140302010)) let b = array.withUnsafeBufferPointer { (buf) -> Int in buf.baseAddress!.advanced(by: 1).withMemoryRebound(to: Int.self, capacity: 1) { (ip) in ip.pointee } } print(String(format: "%016llx", b), b == Int(bitPattern: 0x9941312111403020)) print(MemoryLayout<Int>.size)