Bits

public class Bits

Collection of multiple bits

  • Creates a new instance based on the binary representation of the given variable

    Declaration

    Swift

    public init(byte: UInt8)

    Parameters

    byte

    Value to represent

  • Returns the bit at the given position, starting at the least significant bit

    Example:

    let byte = Bits(byte: 0b1100)
    byte[0] == .zero
    byte[1] == .zero
    byte[2] == .one
    byte[3] == .one
    

    Declaration

    Swift

    public subscript(index: Int) -> Bit { get }
  • Returns the bit at the given position, starting at the most significant bit

    Example:

    let byte = Bits(byte: 0b1100)
    byte[0] == .one
    byte[1] == .one
    byte[2] == .zero
    byte[3] == .zero
    

    Declaration

    Swift

    public subscript(fromMSB index: Int) -> Bit { get }
  • Creates an array of bits, representing the given value

    Declaration

    Swift

    public static func from(byte: UInt8) -> [Bit]

    Parameters

    byte

    Value to represent

    Return Value

    Array of bits