View Full Version : 7.6.5 Applying Offsets to Bits within a Variable or Register
retepsnikrep
- 28th November 2011, 21:16
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?
Charles Linquis
- 29th November 2011, 03:10
Yes, it can.
sayzer
- 29th November 2011, 05:28
.....
Can x be another variable?
Did you mean "Variable" other than Byte in your case, or Value other than 0 ... 7 ?
Charles Linquis
- 29th November 2011, 05:48
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
sayzer
- 29th November 2011, 07:33
x = 125
Config.0[x] = 1
?
Ioannis
- 29th November 2011, 10:10
Maybe bit 5? That is 0.
Ioannis
Charles Linquis
- 30th November 2011, 02:49
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
rsocor01
- 30th November 2011, 03:14
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 = ???
Charles Linquis
- 30th November 2011, 05:59
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.
sayzer
- 30th November 2011, 07:27
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.
:D
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.