Shift Count too large? What?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I have IAR EW 2.28 and do the following:

unsigned long a;
...
a = (1 << 22);
...

And the compiler generates a Warning: "Shift Count too large". Also in the simulator I get 0 as Value for a. But Unsigned long must have 32 Bits or not? Why I can't shift at positions bigger than 15? (15 causes no warning, 16 yes).

Thanks,

Hanns Tappeiner

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

try

a = (1L<<22);

by default literals will be of type char or int. the L will force it to be of type LONG

Writing code is like having sex.... make one little mistake, and you're supporting it for life.