A
Alan Holloway
Hi all,
I'm currently learning C (cliche' entry?) and I am finding bitwise
operations a tad challenging. I have a sound understanding of how
boolean logic works (i think), but I find it hard to evaluate the
constructs when I see them in code.
For example, in a network program, a port number is subjected to the
following operation:
port = (port & 0xff) << 8 | port >>8;
AFAIK, port is being assigned the outcome of :
1) An AND operation to ensure that the variable 'port' is not greater
than 255.
2) A left shift by 8 bits (not too sure why though)
3) An OR with the outcome of a right shift by 8 bits (again, not too
sure why).
My apologies for my obvious lack of clue, but i'd really appreciate
some help here in understanding,
as this has been a bit of a show stopper for sometime, and i've
finally realised i'm probably not going to crack this on my own
Thanks all
Al.
I'm currently learning C (cliche' entry?) and I am finding bitwise
operations a tad challenging. I have a sound understanding of how
boolean logic works (i think), but I find it hard to evaluate the
constructs when I see them in code.
For example, in a network program, a port number is subjected to the
following operation:
port = (port & 0xff) << 8 | port >>8;
AFAIK, port is being assigned the outcome of :
1) An AND operation to ensure that the variable 'port' is not greater
than 255.
2) A left shift by 8 bits (not too sure why though)
3) An OR with the outcome of a right shift by 8 bits (again, not too
sure why).
My apologies for my obvious lack of clue, but i'd really appreciate
some help here in understanding,
as this has been a bit of a show stopper for sometime, and i've
finally realised i'm probably not going to crack this on my own
Thanks all
Al.