Skip to content

Instantly share code, notes, and snippets.

@fcanas
Last active August 29, 2015 14:12
Show Gist options
  • Save fcanas/9a72f1981de4a9a0aa58 to your computer and use it in GitHub Desktop.
Save fcanas/9a72f1981de4a9a0aa58 to your computer and use it in GitHub Desktop.
Flipping Bits
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