News:

;) This forum is the property of Proton software developers

Main Menu

Bit Level Modifier for Variables

Started by streborc, Nov 11, 2026, 10:35 PM

Previous topic - Next topic

streborc

Is there provision in Positron8 for bit level variable modifiers as in:

Dim MyVar as Byte
Dim MyBit as Bit

MyBit = MyVar.3          'Set MyBit to the value of bit 3 of MyVar


If this is valid at the byte level, can this modifier technique be used at the Word, Long and DWord variable level also as in MyVar.12, MyVar.19, and MyVar.29 ?

This is legitimate in PBP, but I cannot find reference to it in Positron's user manual.


DaveS

Hi streborc
  Try 
  SetBit Variable, Index

its in the manual there are others getbit etc
You nearly had it in your question.

DaveS

Stephen Moss

Quote from: streborc on Nov 11, 2026, 10:35 PMIs there provision in Positron8 for bit level variable modifiers as in:

Dim MyVar as Byte
Dim MyBit as Bit

MyBit = MyVar.3          'Set MyBit to the value of bit 3 of MyVar

Yes, the manual section on Aliases states...

QuoteThe Symbol directive is the primary method of creating a constant, and Dim is used to create
an alias to a variable. This is extremely useful for accessing the separate parts of a variable.
Dim Fido as Dog                   ' Fido is another name for Dog
Dim Mouse as Rat.LowByte  ' Mouse is the first byte (low byte) of word Rat
Dim Tail as Rat.HighByte     ' Tail is the second byte(high byte) of word Rat
Dim Flea as Dog.0                ' Flea is bit-0 of Dog, which is aliased to Fido

So if you used the names above, a change to the value of either Fido or Dog results in a corresponding change of Flea, equally if you change the value of Flea then there will be a corresponding change to the relevant bit (in this example bit 0) of Fido & Dog.

Frizie

Ohm sweet Ohm | www.picbasic.nl

streborc

Many thanks to all of your for steering me in the correct direction.  I had been looking on page 31 of the manual that describes splitting larger entities into bytes, and was hoping to find a bit capability there.  I wasn't expecting to find the GET command dedicated to the task.  GET will work nicely for me, especially with its variable index capability.

Stephen Moss

When I wrote my original answer I though you were looking for a fixed relationship, but the example you gave of...
MyBit = MyVar.3 is also valid for one off assignments.
I wrote the following code to take bits from some variables and assign them to bits of another.
Row10.0=C2 : Row10.1=ID_2 : Row10.2=YL.0 : Row10.3=YL.1 :  Row10.4=YL.2 : Row10.5=YL.3 : Row10.6=0 : Row10.7=1YL is one 8-bit variable and Row10 is another.

As @Dave-S indicated Getbit/Setbit also work, the advantage of the commands index variable may really come into play when used within a loop if you need to process multiple bits from a variable.

▲