PDA

View Full Version : Array Indexing



enigma
- 27th December 2006, 20:19
Hi All

I`m have a feeling this can`t be done unless I`ve missed something. I have a bit array containing 16 values of which some I want and some I dont. lets say for now that first 6 are valid, the next two are not, the next 6 are valid for example.
I send these to an LCD using str Values\6. Now the question, is it possible to start again from str Values\8 up to str Values\14 ?. The only way I have thought of so far is to do the second part as a for next loop starting at 8. Is there an easier way here I`ve missed ?.

Cheers Pete

skimask
- 27th December 2006, 23:13
Hi All

I`m have a feeling this can`t be done unless I`ve missed something. I have a bit array containing 16 values of which some I want and some I dont. lets say for now that first 6 are valid, the next two are not, the next 6 are valid for example.
I send these to an LCD using str Values\6. Now the question, is it possible to start again from str Values\8 up to str Values\14 ?. The only way I have thought of so far is to do the second part as a for next loop starting at 8. Is there an easier way here I`ve missed ?.

Cheers Pete


How about copying the bit array to a temp variable, isolate the unused bits out, shift the upper bits down a couple, then recombining the result back into the original?
For instance, 16 bit array in a word, like you said, 1st 6 good, next 2 bad, next 6 good, last 2 bad...

temp1 var word 'original bit array
temp2 var word 'temp bit array

temp2 = temp1 'copy to temp
temp2 = temp2 & %1111110000000000 'isolate upper 6 using AND function
temp1 = temp1 & %0000000000111111 'isolate lower 6 using AND function

temp2 = temp2 >> 4 'shift upper 6 bits down by 4 bits
temp1 = temp1 | temp2 'recombine the 2 using OR function

then spit them out the LCD as you described earlier...