Latest 0.1.0
License MIT
Platforms ios 9.0


This is a simple library for making it easier to access bits and bytes.


Hobbit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Hobbit"

Bit access

Access individual bits and ranges of bits (lsb order) by subscripting any type that conforms to BitwiseAccessible (by default, UInt8 through UInt64).

Individual bits:

let value: UInt8 = 0b00000100
value[0]              // 0
value[1]              // 0
value[2]              // 1
value[3] = 1          // value is now 0b00001100


let value: UInt8 = 0b00000100
value[1...2]          // 0b10
value[2...4] = 0b111  // value is now 0b00011100

Reading bytes from Data

Use a DataReader to read sequential UInts and Strings from a Data instance. Returned values will be nil if the requested data type can’t be read.

let reader = DataReader(data: someData)
guard let id = reader.readUInt8() else { return }
guard let name = reader.readString(bytes: 3, encoding: .nonLossyASCII) else { return }


Hobbit is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "Hobbit",
    "version": "0.1.0",
    "summary": "Tools for working with bits in Swift",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Sam Williams": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.0"
    "platforms": {
        "ios": "9.0"
    "source_files": "Hobbit/Classes/**/*",
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This