Skip to content

Instantly share code, notes, and snippets.

@mollyporph
Last active September 22, 2016 22:12
Show Gist options
  • Save mollyporph/a3f81319c36e0617a359080abea436b8 to your computer and use it in GitHub Desktop.
Save mollyporph/a3f81319c36e0617a359080abea436b8 to your computer and use it in GitHub Desktop.
void Main()
{
int id = 0;
id |= 1 << 11;
id |= 1 << 5;
id |= 1 << 2;
int id2 = 0;
id2 |= 1 << 1;
id2 |= 1 << 5;
id2 |= 1 << 10;
var eqId = 0;
int numMatch = 0;
for (int i = 31; i >= 0; i--)
{
if(((id >> i)& 1) != ((id2 >> i)& 1))
break;
numMatch++;
eqId |= ((id >> i)& 1) << i;
}
eqId >>= 32-(numMatch);
Console.WriteLine($"0b{Convert.ToString(id, 2)}");
Console.WriteLine($"0b{Convert.ToString(id2, 2)}");
Console.WriteLine($"0b{Convert.ToString(eqId, 2)}");
Console.WriteLine(id);
Console.WriteLine(id2);
Console.WriteLine(eqId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment