7 Feb
2017
7 Feb
'17
1:22 p.m.
I was about to complain that 128 fits into 8bits - but of course it doesn’t fit into a signed 8bit int. My bad.
On 8/02/2017, at 10:14 AM, Tom Saxton <tom@idleloop.com> wrote:
For the C18 compiler, an int is 8 bits. In C, all math is done in ints unless forced to a larger type by operands or casting. When you do (1<<7) in an 8-bit int, you shift the bit off the end of the int and get zero. The compiler didn't ignore your constant, it did exactly what it's supposed to do.
You can fix it with a cast, like:
((long)1 << 7) or (1L << 7)
Tom