I have to take an integer of 80 bits in argument, convert it on binary and then make some bit shifts operation on it. I use this snippet (which seems to work fine) to store the argument:
uint64_t n;
seed= strtol(argv[1], &p, 10);
printf("n:%" PRIu64 "\n", n);
Then, I'd like to use this function to convert it to binary:
uint64_t decimal_binary(uint64_t n)
{
uint64_t rem, i=1;
uint64_t binary=0;
while (n!=0)
{
rem=n%2;
n/=2;
binary+=rem*i;
i*=10;
}
return binary;
}
But then:
printf("n:%" PRIu64 "\n", n); /* works fine, even for n >= 1048576 */
printf("n:%" PRIu64 "\n", decimal_binary(n)); /* works only for n <= 1048575 */
I will need to use bit shift operator, so I need a solution which will work with <<
.