From: Jimmy Kofler Date: 2007-03-02T23:05:44+09:00 Subject: C-ish bitwise prime sieve in Ruby? Can we translate the following C-coded prime sieve by Frank Pilhofer into a Ruby version that also uses bitwise operations? Thanks for any suggestions! #include #include #include #include /* Sieve of Eratosthenes. C code by Frank Pilhofer. http://www.fpx.de/fp/Software/Sieve.html */ #define TEST(f,x) (*(f+(x)/16)&(1<<(((x)%16L)/2))) #define SET(f,x) *(f+(x)/16)|=1<<(((x)%16L)/2) int main(int argc, char *argv[]) { unsigned char *feld=NULL, *zzz; unsigned long teste=1, max, mom, hits=1, count, alloc, s=0, e=1; time_t begin; if (argc > 1) max = atol (argv[1]) + 10000; else max = 14010000L; while (feld==NULL) zzz = feld = malloc (alloc=(((max-=10000L)>>4)+1L)); for (count=0; count