Problem with bits in byte array....


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Hi,
    Not sure I follow you Don,
    PutBit is (or is supposed to be) the adress or bit offset into the array, Temp is the logical state to be written to that location. I don't see anything being written to the array in your proposed approach or am I missing something?

    Late last night I made some further tests and at the time it seemed like indexing bits >255 doesn't work....can anyone confirm this? In Melanies classic bits and bytes post/article she mentions using a WORD (PutBit in my case) to index bits in an array of bytes so I would have (did) thought it should work.Anyone knows?

    Thanks!
    /Henrik.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    sorry, I missed where you commented out etc...

    But, in your declare
    Bufferlength con 256 (sets bit 9) 255 is max for byte and
    Buffer VAR Byte[BufferLength] might be set to 0
    Don

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Thanks, but the section covering arrays in the manual says:
    On PIC18 devices, byte, word and long-sized arrays are only limited in length by the amount of available memory. The compiler will assure that arrays, as well as
    simple variables, will fit in memory before successfully compiling.
    My example allocates 265 bytes and one bit, add to that the PBP system vars. It should easily fit in the 1536bytes in the 18F25K20, which is what I'm using by the way, and I'm not getting any errors or warnings.

    My "index-pointers" are WORD sized (becauae I have 256*8=2048 bits in the array) but currently it looks like I can't index bits beyond the 32'nd byte (ie when the index pointer is >255). I haven't seen anyone mention this limitation so I'm not saying this is the case (and I really hope it's not) but currently it's the only thing I can think of.

    Thanks!
    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    OK,
    '
    Code:
     Buffer.0[Putbit] = Temp
    should it be Buffer.0(Putbit) = Temp
    [, vs (

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Thanks Don,
    No, both [] and () should work as far as I know. I tried and it didn't make a difference.

    The problem definitely is in the bit-indexing not allowing me to index above 255....

    Take a look at this example:
    Code:
    Buffer VAR BYTE[256]
    Index VAR WORD
    
    CLEAR
    
    HSEROUT["Buffer[32]: ", DEC Buffer[32],13]
    
    Buffer.0[256] = 1        ' Set LSB of Buffer[32]
    HSEROUT["Buffer[32]: ", DEC Buffer[32],13]
    
    Index = 256
    Buffer.0[Index] = 0     ' Clear LSB of Buffer[32]
    HSEROUT["Buffer[32]: ", DEC Buffer[32],13]
    
    Pause 100
    END
    It gives the following results:

    Name:  Byte_array_problem.jpg
Views: 2576
Size:  25.5 KB

    As you can see, direct/literal indexing the 256'th bit works but doing it thru a variable doesn't. In Melanies example (which may be in error) she states that it should be possible to index bits above 255 this way (as long as the indexing variables is WORD, which it is in my case).

    I have no problem index bytes (as bytes) above 255, it's just this bit-indexing that is screwing with me.

    /Henrik.

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Henrik, thankyou too for explanation.
    A little different approach...........

    1, take 3 bytes at a time (from low array) and place into a LONG, lower 3 bytes, (zero high byte)
    2, left-shift 6 bits, (puts next 6 bits alone in highbyte) place highbyte into array 1/2 way up, clear highbyte, shift again.........
    for a total of 4 times (unpacks 3 base64 packed bytes to 4 bytes as you layed out)
    3, load next 3 bytes to long etc........................up to end

    not sure about padding at the part to have the correct unpacked string.

    Don

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Problem with bits in byte array....

    Hi Don,
    Thank you but I'm doing my very best to avoid LONGs, the code produced by the long version of the compiler is much bigger than the normal even if you're not actually using a single LONG variable. So, I will do my very best to avoid using LONGs as LONG as I can ;-)

    It's not that it can't be done in another way, I had just settled on this and it had me cornered for a while. Now I know what the problem is and I'll aproach it from another angle. Had I bothered to look further back in the manual than the section on arrays I would've found this:
    7.6.4 Accessing Arrays as Multiple Variable-Types
    It is possible for a single array to be declared with multiple names and for each name to be assigned a different variable type. Note that offset for BITs are limited to a maximum value of 255
    To me, that statement is a little vague... I'm indexing a BYTE-array but on a bit basis so the above may apply (apparently) but it DOES work when "manually" indexing it:
    Code:
    Buffer VAR BYTE[64]
    Index VAR WORD
    
    Index=256
    Buffer.0[256] = 1  'Works
    Buffer.0[Index] = 0  ' Doesn't work
    Time to rethink this.

    /Henrik.

Members who have read this thread : 0

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