[Tutor] operators >> and &
Alan Gauld
alan.gauld at btinternet.com
Sun Feb 14 00:58:10 CET 2010
"spir" <denis.spir at free.fr> wrote
> PS: in "l>>24 & 255", the & operation is useless, since all 24 higher
> bits are already thrown away by the shift:
They are not gone however there are still 32 bits in an integer so the top
bits *should* be set to zero. But glitches can occur from time to time...
It is good practice to restrict the range to the 8 bits needed by and'ing
with 255
even when you think you should be safe.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list