Shifting left – a general C question
Hi,
I have a piece of CRC calculating code that I nicked from somewhere a couple of decades ago. I've been wondering about a few lines:
*CRCVal ^= (*CRCVal << 8) << 4;
*CRCVal ^= ((*CRCVal & 0xFF) << 4) << 1;(CRCVal is a pointer to a uint16_t variable.)
What I'm curious about is the slightly weird left-shifting notation. Shouldn't it give exactly the same result if it was written like this?
*CRCVal ^= (*CRCVal << 12);
*CRCVal ^= (*CRCVal & 0xFF) << 5;Does anyone have a hunch why the shifts are split up like this? Could it be something related to a specific compiler or device that handles half-byte shifts in a certain way?
By the way, it would be great if this forum had a "General programming" board. I prefer to ask questions here, as I think that the community has a nice vibe.
