[Ovmsdev] SIM808/SIM908 GPS accuracy

Tom Saxton tom at idleloop.com
Wed Feb 8 05:14:13 HKT 2017

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)


On 2/7/17, 4:30 AM, "Edward Cheeseman" <ovmsdev-bounces at lists.teslaclub.hk on behalf of cheesemanedward at gmail.com> wrote:

    Where normally I’d #define a constant with all its glorious minutes and seconds spelled out, C18 can silently just ignore half of it. I wanted to use +(1<<7) to make clear I was rounding for the >>8 divide.
    It totally ignored that. +128 however did work. I only found that running the MPLAB simulator feeding in values and comparing to a spreadsheet.

More information about the OvmsDev mailing list