Skip to content

Instantly share code, notes, and snippets.

@khellang
Forked from JimBobSquarePants/Xor.cs
Last active November 8, 2018 15:49
Show Gist options
  • Save khellang/04292b0d3be5e94878043e0db0e8f411 to your computer and use it in GitHub Desktop.
Save khellang/04292b0d3be5e94878043e0db0e8f411 to your computer and use it in GitHub Desktop.
Xor combination of two Guids.
public static Guid Xor(Guid a, Guid b)
{
var ad = new DecomposedGuid(a);
var bd = new DecomposedGuid(b);
ad.Hi ^= bd.Hi;
ad.Lo ^= bd.Lo;
return ad.Value;
}
[StructLayout(LayoutKind.Explicit)]
private struct DecomposedGuid
{
[FieldOffset(00)] public Guid Value;
[FieldOffset(00)] public long Hi;
[FieldOffset(08)] public long Lo;
public DecomposedGuid(Guid value) : this() => Value = value;
}
@khellang
Copy link
Author

khellang commented Nov 8, 2018

Yeah, that's what I expected 😄👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment