how to access and set bits in a byte array?


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: how to access and set bits in a byte array?

    pretty much
    bArrRGBData.0[8] is bit 0 of bArrRGBData[0] bit 0 + 8 bits , ie bArrRGBData[1] bit 0
    you can place it in any var but its value can only be 0 or 1
    can also be used as a logical value ie.

    if bArrRGBData.0[8] then dosomething
    else
    doanotherthing
    endif

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,643


    Did you find this post helpful? Yes | No

    Default Re: how to access and set bits in a byte array?

    just a warning pbp does not ckeck the boundary conditions of this type of indexing
    if you were to
    go
    bArrRGBData.0[41] =1
    there is no error message and anything in the next ram/register position from bArrRGBData[4] would be wrecked

  3. #3
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: how to access and set bits in a byte array?

    Quote Originally Posted by richard View Post
    pretty much
    bArrRGBData.0[8] is bit 0 of bArrRGBData[0] bit 0 + 8 bits , ie bArrRGBData[1] bit 0
    you can place it in any var but its value can only be 0 or 1
    can also be used as a logical value ie.

    if bArrRGBData.0[8] then dosomething
    else
    doanotherthing
    endif
    thanks for you help, am removing some rust here due to inactivity
    what bothered me for a bit (pun intended) was whether this would by syntax return a single bit, i realize now that the .0 portion says that and explaining that bArrRGBData.0[8] is equivalent to bArrRGBData[1] bit 0 is just what i needed
    i also understand the risk about overrunning the allocation

  4. #4
    Join Date
    Nov 2003
    Posts
    98


    Did you find this post helpful? Yes | No

    Default Re: how to access and set bits in a byte array?

    how about these cases
    MyWordArray VAR WORD[8]

    what does the following do exactly ?
    MyWordArray = 0
    does it set the first byte of the Array to 0 and leaves the rest as was ?

    what if there is a word variable used instead
    AWord VAR WORD
    MyWordArray VAR WORD[8]
    AWord = 0
    MyWordArray = AWord
    now are the first 2 bytes set to 0 ?
    just curious ....

Similar Threads

  1. How do I check (or set) a group of consecutive bits within a byte?
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 2nd April 2012, 08:13
  2. Problem with bits in byte array....
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th October 2011, 06:27
  3. Access array in PBP and .asm
    By JEC in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th September 2008, 00:35
  4. reading first four bits of a byte
    By kamet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd January 2007, 08:50
  5. Word array behaving like byte array.... wierd
    By forgie in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd August 2005, 15:43

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