0

I've stumbled upon a following problem, could anyone please help? I'm trying to use bitwise operations, and I'm expecting this to print the value of 2^50. The output, however, is 0. The maximum I can get it to print is 2^31, which is supposed to be the maximum of normal int, right? So am I doing something terribly wrong here? Thanks in advance.

#include<stdio.h>
#include<inttypes.h> 
int main(void)  
{
uint64_t x=(1<<50);
printf("%"PRIu64,x);
return 0;
}
Marcin
  • 380
  • 3
  • 20

1 Answers1

4

You have to make your constant an unsigned long long type, which guarantees at least 64 bits in size:

uint64_t x=(1LLU<<50);
2501
  • 25,460
  • 4
  • 47
  • 87