7.6.5 Applying Offsets to Bits within a Variable or Register


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

    Default 7.6.5 Applying Offsets to Bits within a Variable or Register

    I'm a bit confused by this so I'll pose my question.

    I have a byte variable alias called "Config"

    Using the offset bits technique can I manipulate bits by doing

    Config.0[x] = 1

    x being 0 to 7 in this case

    The example in the manual uses a port alias for the demo.

    Can x be another variable?

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


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    Yes, it can.
    Charles Linquist

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    Quote Originally Posted by retepsnikrep View Post
    .....
    Can x be another variable?
    Did you mean "Variable" other than Byte in your case, or Value other than 0 ... 7 ?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    It actually works both ways.

    X var byte
    y var byte
    z var bit

    X = %01010101

    Y = 3
    Z = X.0[Y]
    Z = 0

    Y = 4
    Z = X.0[Y]
    Z = 1
    Charles Linquist

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    x = 125
    Config.0[x] = 1

    ?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    Maybe bit 5? That is 0.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    I don't understand the confusion.

    X var byte
    y var byte
    z var bit

    X = %01010101

    Y = 3
    Z = X.0[Y]
    Z = 0


    X is a variable, Y is a variable. Bit 3 of X is a '0'

    Y = 4
    Z = X.0[Y]
    Z = 1

    Bit 4 of X is 1
    Charles Linquist

  8. #8
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    Quote Originally Posted by Charles Linquis View Post
    I don't understand the confusion.
    Sayzer wants to know what happens if Y > 7. I don't know the answer to that either. For example,

    Y = 8
    Z = X.0[Y]
    Z = ???
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

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


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    It depends on the position of the byte in memory, and is generally unpredictable. You can, however play some tricks with it.
    If you assign vars like -

    X var byte
    Y var byte

    Then PBP will assign the bytes to consecutive memory locations. In that case, bit 8 of X will be bit 0 of Y.
    Charles Linquist

  10. #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: 7.6.5 Applying Offsets to Bits within a Variable or Register

    Quote Originally Posted by rsocor01 View Post
    Sayzer wants to know what happens if Y > 7. I don't know the answer to that either. For example,

    Y = 8
    Z = X.0[Y]
    Z = ???
    I was just referring to the question in the first post.
    I already know that what happens might not be what you would like to get.

    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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