dear beebop,
can you show me the steps?
i'm not understand about bit masks..
thanks!
OK, a bit mask is a word, (or a byte, but here you are using 16 bits) which contains the number you want to check for. You AND that with what ReadKeys() returns. To and it, you use the bitwise operator &.
When you and two words, if any two bit positions are set (logic 1) then the corresponding bit in the result is set.
For example, say you use this:
Code:
#define myKey 0x8000 // same as (1<<15)
if(ReadKeys() & myKey !=0) {
//myKey has been pressed
}
To see how it works, use the binary numbers:
0x8000 = 1000 0000 0000 0000
looking at ReadKeys() it sets the Most Significant Bit
if row 4 key 4 was pressed = 1000 0000 0000 0000
so
1000 0000 0000 0000 &
1000 0000 0000 0000 equals
1000 0000 0000 0000 since the 2 most significant bits were set
if any other key is pressed, say row 2 col 1:
ReadKeys() returns 0000 0000 0001 0000 and when you and this with your bit mask you will get zero:
1000 0000 0000 0000 &
0000 0000 0001 0000 equals
0000 0000 0000 0000
Hope I've explained it well, but if you need more just ask. I need a coffee....