Setting / resetting a variable bit within a byte


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Setting / resetting a variable bit within a byte

    To clear bit 3 in Variable1, I find that

    If Y = 3 -


    The statement:

    Variable1.Y = 0 does not compile, while

    Variable1.0[Y] = 0

    DOES compile - but does it work properly? I don't have any
    hardware to test it on tonight. Even if it does work, is there
    a better way?
    Charles Linquist

  2. #2
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33

    Default

    do it this way
    if y=3 then
    variable.3=0

    ...
    ________________
    KV

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default

    To do it your way, if I had a WORD variable, I would need 16 IF..THENs or 16 CASE statements. There has to be a better way.
    Charles Linquist

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default

    Hi Charles. This .0[x] thing is old news but works very well. It's an undocumended feature.

    I do not think there is a more compact way than this. Why don't you like it?

    Ioannis

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default

    It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

    Thanks!
    Charles Linquist

  6. #6
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Charles Linquis View Post
    It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

    Thanks!
    I'm sure you've seen this thread by Melanie right?

    http://www.picbasic.co.uk/forum/showthread.php?t=544

    A lifesaver thread for sure...

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default

    Quote Originally Posted by Charles Linquis View Post
    It isn't that I don't like it. I just wasn't sure it would work. I thought I remembered the syntax, but when I searched for the technique on the forum for some reason it didn't come up.

    Thanks!
    If you search the forum with the right tool it will reveal the secret!

    look at this:
    http://www.google.com/custom?q=%22.0...picbasic.co.uk

    And from now on you may use the:

    http://www.picbasic.co.uk/forum/showthread.php?t=4751

    to search the forum for sort terms like ".0["

    Ioannis

  8. #8
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default

    I vaguely remembered seeing the solution awhile back, but forgot the details. I do something similar in my own "monitor" program in Code Examples, so I should have known better.

    Melanie doesn't seem to answer as many questions as she used to.

    Melanie, are you there? Is your lack of posts the result of being disgusted with us, or are you busy?
    Charles Linquist

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,104

    Default

    I vote for 2.

    Ioannis

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Posting Permissions

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