Cayenne Lat/Lon Decoder

I am trying to write a decoder for a device that is reporting position in Cayenne LPP format. The basic conversion

decode.lat = (bytes[2] << 16) | (bytes[3] << 8 | bytes[4] ) ;
decode.lat = decode.lat / 10000 ;
decode.lon = (bytes[5] << 16) | (bytes[6] << 8) | bytes[7];
decode.lon = decode.lon / 10000;

works, but does not take into consideration negative values. Given the following test payload

01 88 07 31 1E F0 C8 29 00 DA 5C 02 02 01 8E 03 67 01 40

I think there needs to be logic that looks at the high bit of the first byte of the lat/log triplet to determine whether it is negative, but I haven’t been able to write anything that works. Can someone offer a suggestion?

And worked it out. Replace lines above with

decode.lat = (bytes[4] + (bytes[3]<<8) + (bytes[2]<<16) + (bytes[2] & 0x80 ? 0xFF<<24 : 0)) / 10000;
decode.lon = (bytes[7] + (bytes[6]<<8) + (bytes[5]<<16) + (bytes[5] & 0x80 ? 0xFF<<24 : 0)) / 10000;