I was struggling with a print statement in a program recently which wasn't working as I expected. I kept thinking I had my logic mixed up but eventually it turned out to be an oddity in the 'Print' statement.
It may be 'expected' behaviour, if 'unexpected' for me.
It will print "1" only if the most significant bit of MyByte is set to 1.
So if MyByte has a value > 127: Although this changed when I added an extra line to print spaces to the right of the decimal printed value? See the example program I used to test this.
#Chip18F16Q41,64#OptionExplicit#ConfigCP=On'LCD connection settings#DefineLCD_IO4#DefineLCD_SPEEDFAST#DefineLCD_NO_RW'Port assignments#DefineLCD_RSPortA.0#DefineLCD_EnablePortA.1#DefineLCD_DB4PortA.2#DefineLCD_DB5PortC.0#DefineLCD_DB6PortC.1#DefineLCD_DB7PortC.2DimMyByteAsByteDimMyByteBitAsByteDimReferencedBitAsBitCLSLetMyByte=0DoLocate0,0PrintMyByte.7'These print as expectedPrintMyByte.6PrintMyByte.5PrintMyByte.4PrintMyByte.3PrintMyByte.2PrintMyByte.1PrintMyByte.0Locate0,13PrintMyByte'Print " "'With the above line commented out, prints "1" when MSB set'With the line used, prints "1" when LSB set?Locate1,0LetMyByteBit=7Repeat8PrintMyByte.MyByteBit'This does not print as expected.LetMyByteBit=MyByteBit-1EndRepeatLetMyByteBit=7Repeat8LetReferencedBit=MyByte.MyByteBitPrintReferencedBit'This prints as expectedLetMyByteBit=MyByteBit-1EndRepeatLetMyByte=MyByte+1IfMyByte<1ThenLetMyByte=1EndIfWait100mSLoop
Now I am aware of this, I'm using this in my program:
IfMyByte.MyByteBit=1ThenPrint"1"ElsePrint"0"EndIf
Which is 100% reliable.
At one point "Print MyByte.MyByteBit" printed nothing, not a "1", not a "0", nothing, as though the line was not even present. It was this behaviour that had me most confused.
As I said, it may be that I was trying to do something that isn't possible and that is what actually should happen. I only report it as it gave me half a day of head scratching and confusion.
Last edit: c-conversion 18 hours ago
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was struggling with a print statement in a program recently which wasn't working as I expected. I kept thinking I had my logic mixed up but eventually it turned out to be an oddity in the 'Print' statement.
It may be 'expected' behaviour, if 'unexpected' for me.
This works:
This does not work reliably:
It will print "1" only if the most significant bit of MyByte is set to 1.
So if MyByte has a value > 127: Although this changed when I added an extra line to print spaces to the right of the decimal printed value? See the example program I used to test this.
Test program used:
Now I am aware of this, I'm using this in my program:
Which is 100% reliable.
At one point "Print MyByte.MyByteBit" printed nothing, not a "1", not a "0", nothing, as though the line was not even present. It was this behaviour that had me most confused.
As I said, it may be that I was trying to do something that isn't possible and that is what actually should happen. I only report it as it gave me half a day of head scratching and confusion.
Last edit: c-conversion 18 hours ago
Great insights.
Print MyByte.MyByteBit is working as expected. And your logic is a good approach.