PDA

View Full Version : Lower 4 Bits?



jderson
- 3rd December 2008, 03:47
I am trying to "mask" or "isolate" the lower 4 bits of a byte, and having trouble.I tried using the example on page 26 of the PBP manual:

SecOnes var byte 'should be NIBBLE?
SecOnes = Seconds & $0f

This gives a "Bad Expression" error when compiling. Can someone help, please?
Thank you

Steve_88
- 3rd December 2008, 05:28
Try-
SecOnes var byte 'should be NIBBLE?
Seconds var byte
SecOnes = Seconds & $0f

Or-
SecOnes var byte 'should be NIBBLE?
SecOnes = SecOnes & $0f

jderson
- 3rd December 2008, 14:02
I forgot to add that there already is a SECONDS variable, and it still has the error. Why does it say $0f ???

Bruce
- 3rd December 2008, 14:48
This should not return any errors.


SecOnes var byte
Seconds var byte
SecOnes = Seconds & $0f
Of course the result will be unknown since none of the variables are initialized, but it
definitely should not return an error.


Why does it say $0f ???
Because a value of $0F (%00001111) ANDed with another 8-bit value will return all
0's in the upper 4-bits of the result MASKing the upper 4-bits out.

jderson
- 3rd December 2008, 15:32
Thank you, Bruce for the explanation. I now understand how it works. I failed to explain that I'm trying to "add-on" (within the Main portion of my program) to DT's Elapsed_INT-18. That's why I said the Seconds variable was already declared. So, when I declare it again, I get the redefinition error. I'll try adding the SecOnes stuff to HIS program!