Checking Bit of a Byte using another variable


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default Checking Bit of a Byte using another variable

    If I have two byte variables Check and Days.
    If Days only range from 1 to 7, can we check bits in Check based on Days?

    For example, lets say if Days=5, I am having trouble with the following method:

    Code:
    if Check[Days]=1 then goto whatever
    In the above example I want to check bit 5 of Check variable.

    Is there any other method to do the above task?
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Is there any other method to do the above task?
    Yes:

    if Check.0[Days]=1 then goto whatever

    Cheers

    Al.
    All progress began with an idea

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post

    if Check.0[Days]=1 then goto whatever

    Al.
    Thanks Al, can you please explain what does "0" in Check.0 does?
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Check.0[Days] tells PBP to treat Check as a bit array with Days as the bit index pointer.

    Since Check is a byte PBP will treat it as an 8-bit array. The lowest bit will be 0, and the
    highest bit will be 7.

    If Days = 5; then IF Check.0[Days]=1 will be testing bit position 6 in Check if you're
    counting bit positions in Check from left-to-right as 87654321.

    Then you would use; IF Check.0[Days-1]=1 THEN.

    If you're counting bit positions in Check from left-to-right as 76543210 then it would work
    with; IF Check.0[Days]=1 THEN.
    Last edited by Bruce; - 10th December 2010 at 23:13. Reason: Better explanaition
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Default little confused

    Quote Originally Posted by Bruce View Post
    Check.0[Days] tells PBP to treat Check as a bit array with Days as the bit index pointer.

    Since Check is a byte PBP will treat it as an 8-bit array. The lowest bit will be 0, and the
    highest bit will be 7.

    If Days = 5; then IF Check.0[Days]=1 will be testing bit position 6 in Check if you're
    counting bit positions in Check from left-to-right as 87654321.

    Then you would use; IF Check.0[Days-1]=1 THEN.

    If you're counting bit positions in Check from left-to-right as 76543210 then it would work
    with; IF Check.0[Days]=1 THEN.
    Thanks for the explanation, few clarifications:
    1) Do bits get counted from right to left OR left to right?
    I mean to say isn't that Check.0[Days]=1 should check bit 4? (Assuming Days=5)
    2) What can I do if Check is a word and I want to check:
    a) Bit 15 & Bit 3 (Just want to know)
    b) Lower byte value & higher byte value
    ___________________
    WHY things get boring when they work just fine?

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce, the topics have really been helpful.
    After reading them, I still have one question (Just want to confirm)

    Please correct me if I am wrong :

    Check=[bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0]

    To access bit7 of Check variable (byte) : Should it be
    Check.0[days] ; Days =7 in this example

    Similarly :

    To access bit1 of Check variable (byte) : Should it be
    Check.0[days] ; Days =1 in this example
    ___________________
    WHY things get boring when they work just fine?

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Yep that will work.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 1

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