I'm trying to understand why this programm after 2^20-1 value goes in overflow. All my variables are declared unsigned long long, but when I enter 1048756 which is 2^20 it goes in overflow , instead of converting it in a binary number. I thought that the range of u-l-l was 2^64-1. I included the limits.h library and the maximum value was 8 bytes.This is the code :
#include <stdio.h>
int main(){
unsigned long long n = 100000000;
printf("%llu \n",decimal_binary(n));
return 0;
}
unsigned long long decimal_binary(unsigned long long n)
{
unsigned long long rem, i=1, binary=0;
while (n!=0)
{
rem=n%2;
n/=2;
binary+=rem*i;
i*=10;
}
return binary;
}
And the output is :
14184298036271661312
(Which is not a binary number obviously)