Slide 11
Slide 11 text
όΠτྻΛIntܕʹม͢Δ֦ு
extension FixedWidthInteger {
init(bytes: UInt8...) {
self.init(bytes: bytes)
}
init(bytes: T) {
let count = bytes.count - 1
self = bytes.enumerated().reduce(into: 0) { (result, item) in
result += Self(item.element) << (8 * (count - item.offset))
}
}
}
XCTAssertEqual(UInt16(bytes: 0x35, 0x0B), 13579)
XCTAssertEqual(Int(bytes: 0x07, 0x5B, 0xCD, 0x15), 123456789)