ganimides wrote:Could you help to understand what does these code lines do?Let`s suppose KBD_MAX_ROW=41) temp = (1 << KBD_MAX_ROW) - 1 Is this code line equal to 7 (0111)?2)Let`s suppose KBD_COL_DDR= DDRA and KBD_COL_PORT =PORTA
KBD_COL_DDR |= temp; What is the meaning of this notation?
KBD_COL_PORT &= ~temp; What is the meaning of this notation?
1) temp = (1 << KBD_MAX_ROW) - 1
= (%00010000) - 1
= %00001111 or 15 decimal
2a) KBD_COL_DDR |= temp;
is shorthand for
KBD_COL_DDR = KBD_COL_DDR | temp;
This sets one or more bits in accordance with the mask value held in temp.
2b) KBD_COL_PORT &= ~temp;
is shorthand for
KBD_COL_PORT = KBD_COL_PORT & ~temp;
This clears one or more bits in accordance with the mask value held in temp.
Regards,
Mac
Seeing how I was invited and all, I will attempt to make it even a little clearer:
1 << KBD_MAX_ROW
is 1 << 4
<< means left shift the thing on the left by the number of bits on the right
(shift 1 to the left 4 times)
now look at rhino's binary example.
As for the other two, refer to bigmac's expansions then note that:
| means bitwise OR 00001010 | 00000011 = 00001011
& means bitwise AND 00001010 & 00000011 = 00000010
~ means one's complement (NOT) ~00001010 = 11110101
(values chosen are arbitrary)
Then read bigmac's beautifully concise one sentence explanation for their most common use.
Regards David
Message Edited by peg on 2006-07-29 09:29 AM