Quick question about indexed variables
I have read the help file a couple of times about using indexed variables and about the only thing I can come up with is I must have something else wrong in my theory on how these work.· What I am trying to do is create a 8 bit indexed bit.· I then try to compair it with a second nib and I can not get them to compair anything but the last bit (number 8).· Also, When I try to debug the variable I can not get the entire variable to debug at one time; basically I have to put the bit behind it each time?· Can someone tell me what I need to put behind the variable to debug or compair the entire thing?
Number· ·VAR·· Bit(8)
Index··· · VAR· Bit(8)
If Number=Index then goto Update:
Update:
DEBUG BIN·Number
What would I put in () behind Number and Index to compare all of the bits?
Second quick question, when I am compairing the two variables is there a command that will make it go to say sub1 if bit1 is different, or sub2 if bit2 was different, and so on?
Thanks for all the help in advance!· James
·
Number· ·VAR·· Bit(8)
Index··· · VAR· Bit(8)
If Number=Index then goto Update:
Update:
DEBUG BIN·Number
What would I put in () behind Number and Index to compare all of the bits?
Second quick question, when I am compairing the two variables is there a command that will make it go to say sub1 if bit1 is different, or sub2 if bit2 was different, and so on?
Thanks for all the help in advance!· James
·
Comments
In the case of a byte variable, you should be able to address each of the 8 bits with BIT0, BIT1, BIT2... BIT7.
I believe when you either compare what you've done in your "IF" statement or perform a DEBUG of those variables without specifying a "subscript", you are implying the 0th element in the array. I believe that would be the first in the sequence, not the last.
In any case, you should be able to loop through comparing each element or bit one at a time. Depending on what you are trying to achieve, there are bitwise operators such as OR, AND and XOR that may get you what you want. So for your second question, an XOR could compare two 8 bit variables and result in a '1' for each bit that differed and a '0' for those cases where they are the same. So let's say variable one was %10101010 and variable two was %11001111. The XOR of these two would return %01100101. Now you can jump to a label depending on what BIT0, BIT1, BIT2.... BIT7 are. Understand that the bits number from right to left, so 7,6,5,4,3,2,1,0. This could explain why you might be getting only the last bit of your variable also.
value1 VAR Byte
value2 VAR Byte
result VAR Byte
value1 = %10101010
value2 = %11001111
result = value1 ^ value2
If result.bit7 then goto label1
....
If result.bit6 then goto label2
....
label1:
....
label2:
....
Of course a direct compare (if value1 = value2) would compare the entire variables to one another.
Maybe this will give you some ideas.
Rick
Ditto on Rick's suggestions.
You first define value1 and value2 at bytes, and after that there are several ways that you can get at the individual bits.
value1 VAR Byte
value2 VAR Byte
v1b0 VAR value1.bit0 ' give indiviual bits alias names
v1b1 VAR value1.bit1
' ...
v1b7 VAR value1.bit7
IF v1b5 = 0 THEN ... ' use the alias name directly
IF v1b0(5) = 0 THEN ' this implied array syntax is the same as v1b5 = 0
IF v1b0(idx) = 0 THEN ' and for loops the index can be a variable.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com