Using 1 bit variables in Propbasic
jnogues
Posts: 25
Hi All,
In the last month I'm trying diferents ways to use 1 bit variables in propbasic, but I can't do it.
I only need evaluate a a lot of boolean functions like: Result=(Var1 OR Var2) AND Var3.
Somebody have an idea for me? I'm desesperated!!
Regards,
Jaume Nogues
Barcelona
Spain
In the last month I'm trying diferents ways to use 1 bit variables in propbasic, but I can't do it.
I only need evaluate a a lot of boolean functions like: Result=(Var1 OR Var2) AND Var3.
Somebody have an idea for me? I'm desesperated!!
Regards,
Jaume Nogues
Barcelona
Spain
Comments
what is the exact reason, that you cannot just waste 31 bits and use long variables? ((The Prop is made for longs and so is PropBasic.))
The calculations have to be done with longs. So I would write one function
ReadBitArray(BitNumber)
and one Sub
WriteBitArray(Bitnumber, Value)
The BitArray could be located in Cog or main ram and it could have one or more longs as length.
Would this approach be possible?
Christof
As Christof has stated, the propeller doesn't have any bit operators. It would take more ram for instructions to do bit variables, than just using a LONG. So PropBasic makes you use a LONG.
If all of your variables are either 0 or 1. Then you can do the operation with LONGs.
Result = Var1 OR Var2
Result = Result AND Var3
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
I think my problem is usin arrays in propbasic. In the next program I want to writte a state
on leds 23 to 16.
If I use:
I(0)=STATE 'WORK
LEDs=I(0)
works OK!
But if I use
I(1)=STATE 'DONT WORK
LEDs=I(1)
Why? I don't understand it!!
Here you have the complert program:
'***********************************************************
DEVICE P8X32A, XTAL1, PLL16X
XIN 5_000_000
LEDs PIN 23..16
IN1 PIN 0
IN2 PIN 1
IN3 PIN 2
I VAR LONG(16)
Q VAR LONG(16)
STATE VAR LONG
Start:
OUTPUT LEDs
Main:
STATE=%00000000_00000000_00000000_10100000
DO
I(0)=STATE 'WORK
LEDs=I(0)
'I(1)=STATE 'DONT WORK
'LEDs=I(1)
LOOP
END
'*********************************************************
You can only assign a PIN variable from a simple VAR not an array.
I(0) is the same as I, so that works. You should get an error message with I(1), I'll look into that. Maybe I can allow an array element.
The easiest thing is to use: (as a work around)
__temp1 = I(1)
LEDs = __temp1
Bean
[noparse][[/noparse]EDIT] I discovered that this is a bug in the compiler. It will be corrected in version 00.00.96.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 4/27/2010 9:04:29 PM GMT
Jaume
I looked at the compiler and what you found is indeed a bug. Your code should have worked as you originally wrote it.
I will fix this in the next release.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
Post Edited (Bean) : 4/27/2010 9:05:00 PM GMT