Skip to content

Commit

Permalink
Add bitduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjaclasher committed Apr 11, 2019
1 parent 6f47ea3 commit 5bff4d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
DMOJ/cerc2000h.py
DMOJ/phantomc1.py
DMOJ/bitduplication.cpp
16 changes: 16 additions & 0 deletions DMOJ/bitduplication.cpp
@@ -0,0 +1,16 @@
unsigned long long tmp;

unsigned long long duplicatebits(unsigned long long n)
{
tmp = (n ^ (n >> 16)) & 0x00000000ffff0000;
n ^= (tmp ^ (tmp << 16));
tmp = (n ^ (n >> 8)) & 0x0000ff000000ff00;
n ^= (tmp ^ (tmp << 8));
tmp = (n ^ (n >> 4)) & 0x00f000f000f000f0;
n ^= (tmp ^ (tmp << 4));
tmp = (n ^ (n >> 2)) & 0x0c0c0c0c0c0c0c0c;
n ^= (tmp ^ (tmp << 2));
tmp = (n ^ (n >> 1)) & 0x2222222222222222;
n ^= (tmp ^ (tmp << 1));
return n | (n << 1);
}

0 comments on commit 5bff4d6

Please sign in to comment.