Skip to content

Instantly share code, notes, and snippets.

@fbstj
Created January 11, 2012 19:28
Show Gist options
  • Save fbstj/1596318 to your computer and use it in GitHub Desktop.
Save fbstj/1596318 to your computer and use it in GitHub Desktop.
detects strings who's characters are in a Grey-code sequence
// detects strings whos bytes are greycoded
function greystring(str){
var a, b
function bitcount(v){
var c;
for (c = 0; v; c++)
v &= v - 1;
return c;
}
for(var i = 1; i < str.length; i++)
{
a = str.charCodeAt(i - 1)
b = str.charCodeAt(i)
if(bitcount(a ^ b) > 1)
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment