Menu

adressing single bit in array

2013-09-26
2018-01-24
  • polyconnect

    polyconnect - 2013-09-26

    Hi there,

    What would be the syntax to address a single bit in an array ?
    I've tried :

    video_buffer_A1(video_adress).pixel = 1

    video buffer is an array of 64 bytes, and pixel is a number between 0 and 7

    doesn't seem to work...

     

    Last edit: polyconnect 2013-09-26
  • Anobium

    Anobium - 2013-09-27

    Can you clarify? because I am confused by your question.

    'video_buffer_A1' is the array name.
    'video_adress' is the pointer to an element in the array 'video_buffer_A1'.
    So, to assign an element you would use
    var1 = video_buffer_A1(element)

    You can then obtain the bits of var1 by
    var1bit = var1.1 : ' where .1 is the pointer to the bits.

    So, what are your trying to achieve?

     
  • polyconnect

    polyconnect - 2013-10-02

    Thanks for your answer. It helped ;)

    According to the FAQ in the help file :

    "Can I specify the bit of a variable to alter using another variable?
    No. Set variable.othervariable On may not generate an error, but it will not act as expected."

    Does anybody know why is that ? It would make it easier for everyone no ?

     
  • Anobium

    Anobium - 2013-10-02

    Sorry, I do not know the answer.

    I have not seen any references to variable referential addressing. I am aware of referential addressing for ports.

     
  • Hugh Considine

    Hugh Considine - 2013-10-02

    This limitation comes from the way that GCBASIC addresses individual bits. On a PIC, it uses btfss, btfsc, bsf and bcf instructions, all of which require the individual bit to be hard coded. One workaround is some code like this:

    'Prepare a bit mask with only the correct bit set
    TempMask = 0
    Set C On
    Repeat Pixel
        Rotate TempMask Left
    End Repeat
    'OR with array element to set bit there
    video_buffer_A1(video_adress) = video_buffer_A1(video_adress) Or TempMask
    

    To clear a bit, you'd need similar code (but start with TempMask = 255, C = Off, and an And rather than an Or in the array set.)

     
  • polyconnect

    polyconnect - 2013-11-20

    nice. I use the mask trick quite often now. Made an array of 8 bytes with one bit ON at the time and use the array(variable) to mask my bytes. It's good to learn.

     
  • polyconnect

    polyconnect - 2018-01-24

    simple naive question : could this be potentially taken care of by the compiler ? i mean could we use the simple adressing syntax with a variable in our code and let the compiler do all the masking tricks ?

     
    • Anobium

      Anobium - 2018-01-24

      As we have a method to addressn array bit within the current compiler constraint the investment (in time to develop and test) may not be worth benefit.

      However, I have added to the list of the potential future changes.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.