Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created November 4, 2017 23:22
Show Gist options
  • Save benaryorg/7b4aa86677000cac03ac1f779f975e4b to your computer and use it in GitHub Desktop.
Save benaryorg/7b4aa86677000cac03ac1f779f975e4b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#define xor_to(x) _xor_to((x),0,0)
long long _xor_to(long long to,long long cur,long long acc)
{
cur+=1;
if(cur > to)
{
return acc;
}
acc^=cur;
return _xor_to(to,cur,acc);
}
int main(int argc,char **argv)
{
assert(argc == 2);
long long i=atoll(argv[1]);
printf("%llx\n",xor_to(i));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment