• Create Account

### #Actualalvaro

Posted 16 October 2012 - 09:25 AM

y=0; //clear y
t=0;
for (int i=0;i<64;i+=2)
if (x & (CONTAINER_INT(1) << (i%ContainerSize)))
{
y |= CONTAINER_INT(1) << (t%ContainerSize);
t++;
}


y = (CONTAINER_INT(1)<<popcount(x & 0x555555555555555ul)) - 1;

EDIT: popcount stands for "population count", which means count the number of bits set. gcc provides __builtin_popcount for you, or you can use one of the tricks described in Bit Twiddling Hacks. Oh, and I am not sure why you are doing %ContainerSize'.

### #2alvaro

Posted 16 October 2012 - 09:24 AM

y=0; //clear y
t=0;
for (int i=0;i<64;i+=2)
if (x & (CONTAINER_INT(1) << (i%ContainerSize)))
{
y |= CONTAINER_INT(1) << (t%ContainerSize);
t++;
}


y = (CONTAINER_INT(1)<<popcount(x)) - 1;

EDIT: popcount stands for "population count", which means count the number of bits set. gcc provides __builtin_popcount for you, or you can use one of the tricks described in Bit Twiddling Hacks. Oh, and I am not sure why you are doing %ContainerSize'.

### #1alvaro

Posted 16 October 2012 - 09:21 AM

y=0; //clear y
t=0;
for (int i=0;i<64;i+=2)
if (x & (CONTAINER_INT(1) << (i%ContainerSize)))
{
y |= CONTAINER_INT(1) << (t%ContainerSize);
t++;
}


y = (CONTAINER_INT(1)<<popcount(x)) - 1;

PARTNERS