K
Kenneth Lantrip
Im trying to learn a little more about C compilers.
Im trying to work with 64 bit numbers (integers) with the gcc compiler
in linux (ubuntu). I need to know how to make use of 64 bit numbers.
My test program as follows:
-----------------------------------------------------------------
#include <ncurses.h>
#define sleep(x) usleep(x * 1000) // adjust sleep functions to
milliseconds
typedef unsigned char byte; // values are 0-255
#define wlen 43 // how many bits long we are
interested in
int Int2Bin(int x, byte *y) {
int i, j;
y += wlen; *y-- = 0; j = 0;
for (i = 0; i < wlen; i++) {
*y-- = 48 + (x & 1);
if (x & 1) j = i + 1;
x >>= 1;
}
return j;
}
int CountOnes(byte *x) {
int i;
i = 0;
do {
i += 1 & (*x++ == 49);
} while (*x != 0);
return i;
}
int main(void) {
static long long Count = 1, t = 0x1FFFFF;
static byte bits[64];
initscr();
noecho();
do {
Int2Bin(t++, bits);
if (CountOnes(bits) == 21) {
printw("%s :: Count = %d\n", bits, Count++);
refresh();
}
} while (t < 0x7FFFFC00000); // error here over long
getch();
endwin();
printf("\nTest program completed successfully.\n\n");
return 0;
}
Im trying to work with 64 bit numbers (integers) with the gcc compiler
in linux (ubuntu). I need to know how to make use of 64 bit numbers.
My test program as follows:
-----------------------------------------------------------------
#include <ncurses.h>
#define sleep(x) usleep(x * 1000) // adjust sleep functions to
milliseconds
typedef unsigned char byte; // values are 0-255
#define wlen 43 // how many bits long we are
interested in
int Int2Bin(int x, byte *y) {
int i, j;
y += wlen; *y-- = 0; j = 0;
for (i = 0; i < wlen; i++) {
*y-- = 48 + (x & 1);
if (x & 1) j = i + 1;
x >>= 1;
}
return j;
}
int CountOnes(byte *x) {
int i;
i = 0;
do {
i += 1 & (*x++ == 49);
} while (*x != 0);
return i;
}
int main(void) {
static long long Count = 1, t = 0x1FFFFF;
static byte bits[64];
initscr();
noecho();
do {
Int2Bin(t++, bits);
if (CountOnes(bits) == 21) {
printw("%s :: Count = %d\n", bits, Count++);
refresh();
}
} while (t < 0x7FFFFC00000); // error here over long
getch();
endwin();
printf("\nTest program completed successfully.\n\n");
return 0;
}