PDA

View Full Version : FYI - How to Access individual bytes in Word Arrays



Melanie
- 20th July 2003, 22:56
We all know that we can access the highbyte and lowbyte of a word like so...

mybyte=myword.highbyte
mybyte=myword.lowbyte

it is not too obvious how to achieve this when myword is an array... consider...

myword var word (10)

executing the statement...

mybyte=myword.highbyte(5)

you would think would return the highbyte of myword(5) in the array, but not so...

The relationship actually is...

myword.highbyte(x*2) = the highbyte of myword(x)
myword.lowbyte(x*2) = the lowbyte of myword(x)

So the answer to accessing the highbyte of myword(5) in an array using the highbyte (or lowbyte) expression is actually...

mybyte=myword.highbyte(10)

As an afterthought (as my explaination confused one person and it tests editing threads as well) it should be considered that when accessing word arrays using highbyte and lowbyte, your array access changes from word to BYTE, that's why you have to skip every other byte.

Melanie