github.com/Cosmo/BinaryKit

0️⃣1️⃣ Access bits and bytes from binary data in Swift.


Keywords
binary, binary-data, bit, bits, byte, bytes, data, nsdata, swift
License
MIT

Documentation

 text

BinaryKit

Access bits and bytes directly in Swift.

Usage

Initialize from NSData

let data   = NSData(...)
let binary = Binary(data: data)

or [UInt8] bytes array

let binary = Binary(bytes: [0xDE, 0xAD]) // 1101 1110 1010 1101
// Bits
binary.bit(0) as Int      // 1
binary.bit(1) as Int      // 1
binary.bit(2) as Bit      // .Zero
binary.bit(3) as Bit      // .One
binary.bits(0, 16)        // 57005 

// Bytes
binary.byte(0) as Int     // 222
binary.bytes(0, 2) as Int // 57005

Todos

  • Endianness flag
  • Tests
  • Documentation

License

BinaryKit is released under the MIT License.