Last active
August 29, 2015 14:12
-
-
Save fcanas/9a72f1981de4a9a0aa58 to your computer and use it in GitHub Desktop.
Flipping Bits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func flipOn<T: RawOptionSetType>(value: T, change: T) -> T { | |
return T(rawValue: value.rawValue | change.rawValue ) | |
} | |
func flipOff<T: RawOptionSetType>(value: T, change: T) -> T { | |
return T(rawValue: value.rawValue & ~change.rawValue ) | |
} | |
func toggle<T: RawOptionSetType>(value: T, change: T) -> T { | |
return T(rawValue: value.rawValue ^ change.rawValue ) | |
} | |
func bitSetter<T: RawOptionSetType>(value: Int) -> (T,T)->T { | |
if value==1 { | |
return flipOn | |
} else { | |
return flipOff | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment