In need of accessing more than 255 bits in a byte/word array.

# Thread: In need of accessing more than 255 bits in a byte/word array.

1. ## In need of accessing more than 255 bits in a byte/word array.

Hello all.

I'm sure this question has been asked a million times before but has anyone found a way to access more than 255 bits in a byte/word array with a variable bit index?

Any and all answers are appreciated.
Last edited by csantex; - 16th January 2019 at 03:37. Reason: Display error, typos

2. ## Re: In need of accessing more than 255 bits in a byte/word array.

value
bit = array[abc/8]&(1<<(abc//8))
to set
array[abc/8]= array[abc/8] |(1<<(abc//8))
to clear
array[abc/8]= array[abc/8] & ~(1<<(abc//8))

3. ## Re: In need of accessing more than 255 bits in a byte/word array.

Thanks Richard. I already use a similar approach to set and clear the bits within my array but it's not as elegant as yours.

Code:
```    BrdCountLp0 = Address/16       ; I divide by 16 to select the array variable I want.
BitCountLp0 = Address//16      ; Now I get the remainder of the division above and it becomes my bit number.
lookup2 BitCountLp0, [\$01,\$02,\$04,\$08,\$10,\$20,\$40,\$80,\$100,\$200,\$400,\$800,\$1000,\$2000,\$4000,\$8000], TempBits
.
.
.
.

TempBits0 = ~TempBits0
OutputLp0[BrdCountLp0] = OutputLp0[BrdCountLp0] & TempBits ; AND these two to clear the bit.

or

OutputLp0[BrdCountLp0] = OutputLp0[BrdCountLp0] | TempBits ; OR these two to set the bit.```
The heart of this post is to see if I could read the status of all the bits in my array, in a loop. My max array is 32 words, so 512 bits. I could split my array in two 16 word arrays but that just complicates things.
I will see how I can make your value expression work for me in a loop.

Thanks

5. ## Re: In need of accessing more than 255 bits in a byte/word array.

another way is to stick with a byte array any use an asm call to the L?CALL ARRAYBIT ,macro after setting fsr to appropriate offset
and calculated byte index for testing bit set or not,. bit offsets of any size in any sized array can be accomodated

Code:
```  movlw   high (_leds) ;Store the High byte of leds to FSRH [set fsr to (bit/256)*256 offset
movwf   FSR0H
movlw   low (_leds)
movwf   FSR0L        ;Store Low byte of leds in FSRL
decf   _x,W  [this is the index   [bit//256
bcf STATUS,C         ;must clear carry before arraybit call
L?CALL ARRAYBIT      ;inc fsr to correct byte and test bit
bz NL```

6. ## Re: In need of accessing more than 255 bits in a byte/word array.

Thanks for the link sayzer! I have read it before a long time ago and it was very helpful at the time. As it turns out, the method stated by melanie does not coincide with what the manual states. I tried it in a for loop and I could only read 255 bits out of 512. These bits are used as flags and when one is set, I turn on an output for a specified period of time using interrupts. In the interrupt, I would check the flags and if they were set, I would then clear my output and the flags until they get set again. It would.be best to use a loop, although not specifically needing to be a for loop. I will try Richard's example and see if it will work. If you have any other suggestions, I'm all "ears". Thanks again for your input.

7. ## Re: In need of accessing more than 255 bits in a byte/word array.

I tried it in a for loop and I could only read 255 bits out of 512.
the arraybit macros are byte sized

#### Members who have read this thread : 19

You do not have permission to view the list of names.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts