Skip to content

Instantly share code, notes, and snippets.

@jedy
Created June 15, 2015 02:14
Show Gist options
  • Save jedy/5e7b4d797121fbdd85da to your computer and use it in GitHub Desktop.
Save jedy/5e7b4d797121fbdd85da to your computer and use it in GitHub Desktop.
gray code
func BinaryToGray(num uint) uint {
return (num >> 1) ^ num
}
func GrayToBinary(num uint) uint {
for mask := num >> 1; mask != 0; mask = mask >> 1 {
num = num ^ mask
}
return num
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment