Accessing a byte within an array of longs.
W9GFO
Posts: 4,010
I know you can access a particular byte within a long like this: MyVar.byte[noparse][[/noparse] 2]
How can you address a byte within a long that is part of an array?
VAR long MyVar[noparse][[/noparse]100]
MyVar[noparse][[/noparse]23].byte[noparse][[/noparse] 2] does not work.
Also, how can I look at just one bit in an array of longs?
Rich h
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 6/20/2010 12:14:46 AM GMT
How can you address a byte within a long that is part of an array?
VAR long MyVar[noparse][[/noparse]100]
MyVar[noparse][[/noparse]23].byte[noparse][[/noparse] 2] does not work.
Also, how can I look at just one bit in an array of longs?
Rich h
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 6/20/2010 12:14:46 AM GMT
Comments
-Phil
So does MyVar.byte[noparse][[/noparse]23] point to the 24th byte in the array which is byte 3 of MyVar[noparse][[/noparse] 6]?
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Now, is there an equally simple way to look at a single bit within an array?
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
if (byte[noparse]/noparse]@myvar[noparse][[/noparse]23[noparse][[/noparse]2] >> 4) & 1
· 'this bit is a 1
else
· 'this bit is a 0
The 4 in the if statement above is the bit position(0 - 7)·you pick to check. But I'm not a expert so maybe one of the gurus here can step in and show us a better way!
edit: thats looking at bit position 4(0-7) of the 3rd byte of the 24th long in myvar[noparse]/noparse
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
Post Edited (ratronic) : 6/20/2010 3:51:34 AM GMT
if myvar[noparse][[/noparse]23] & $10_00_00_00 '(%00010000_00000000_00000000_00000000)
'bit 4 of byte 3 of the 24th long in the array is a 1
else
'bit 4 of byte 3 of the 24th long in the array is a 0
Or a maybe this is simpler;
if myvar[noparse][[/noparse]23] >> 28 & 1
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
It saves having to do the shift at run-time.
-Phil
if (myvar[noparse][[/noparse]23] >> 28) & 1·
the >> 28 gets the bit you want shifted to bit position 0·, the & 1 masks out any other bits than bit position 0. With a long, bit positions are 0 - 31 (32 bits). Also notice where the parenthesis are placed
Edit: = thanks Phil, I was hoping somebody would show a better way!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
···································Fix it, if ain't broke!
D Rat
Dave Ratcliff N6YEE
CON
GLAXORBIT = 1 << 28
...
if (myvar[noparse][[/noparse]*28] & GLAXORBIT)
Plus, if you decide GLAXORBIT needs to be located somewhere else, you've got only the CON statement to change.
-Phil
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
Post Edited (W9GFO) : 6/20/2010 6:22:32 AM GMT