Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Unsigned Long Long - weird output

OK, I'm trying to print the decimal/hexadecimal version of a relatively big unsigned long long and the results I'm getting are quite weird...

The code :

unsigned long long a = 1llu<<63;

printf("decimal = %llu\n",a);
printf("hexadecimal = %llx\n",a);

The output :

decimal = 9223372036854775808
hexadecimal = 8000000000000000

Now, here's what :

Why's that happening? What am I doing wrong???

Upvotes: 1

Views: 370

Answers (1)

Potatoswatter
Potatoswatter

Reputation: 137800

Since five is not a factor of any power of two, no power of two ends in zero. Your other source which gave 9223372036854780000 is incorrect.

Upvotes: 8

Related Questions