jweinst1
2/24/2016 - 5:50 AM

bit struct in swift

bit struct in swift

struct Bit {
    var state:Int
    
    init(state:Int) {
        assert(state == 0 || state == 1)
        self.state = state
    }
    //flips the bit
    mutating func flip() {
        if self.state == 0 {
            self.state = 1
        }
        else {
            self.state = 0
        }
    }
}