/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>

void test(int v)
{
   int offset;
   int v2 = v;
   v2 = (v2 - 0x01010101) & ~v2;
   v2 = v2 & 0x80808080;
   printf("%08X %08X\n",v,v2);
   if(v2!=0)
   {
       offset = (v2 - 1) & 0x04040400;
       offset = offset + (offset << 8) + (offset << 16);
       offset = offset >> 26;
       printf("%d\n",offset);
   }
   return;
}

int main()
{
   test(0x12345678);
   test(0x00345678);
   test(0x12005678);
   test(0x12340078);
   test(0x12345600);
   return 0;
}
