View previous topic :: View next topic |
Author |
Message |
RWo
Joined: 23 Sep 2015 Posts: 22
|
Posted: Mon Oct 19, 2015 1:58 pm Post subject: ...need some help to Logical operators NOT OR |
|
|
...see the samples below. I don't get the sence of them.
Code: |
$Regfile="m32def.dat"
$Crystal=14745600
$hwstack = 40
$swstack = 16
$framesize = 64
$baud = 19200
$sim
Const RWcDebug = 0
Dim Test(4) as Byte
Dim Test1 as Bit, Test2 as Bit
Do
'( Sampe 2
#If NOT RWcDebug 'NOT is ignored
If Test(1) < 254 then Incr Test(1)
If Test(2) < 254 then Incr Test(2)
#EndIf
#If RWcDebug
#Else
If Test(1) < 254 then Incr Test(1)
If Test(2) < 254 then Incr Test(2)
#EndIf
')
'( Sample 2
If NOT Test(3) then 'NOT create Error 35
Test(3) = 1
End If
If NOT Test(3) = 1 then 'NOT create Error 35
Test(3) = 1
End If
')
'( Sample 3
If Test(3) OR Test(4) then '...create Error 35
Test(3) = 1
End If
If Test(3) = 0 OR Test(4) = 0 then '...but here, OR works fine
Test(3) = 1
End If
Test(3) = 1
')
'( Sample 4
If NOT Test1 then 'NOT create Error 35
Set Test1
End If
If NOT Test1 = 1 then 'NOT create Error 35
Set Test1
End If
')
' Sample 5
'If Test1 OR Test2 then 'OR create Error 35
' Set Test1
'End If
If Test1 = 0 OR Test2 = 1 then 'this works ? but why need "=0" is a binary anyway
Set Test1
End If
Loop
End
|
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon Oct 19, 2015 7:26 pm Post subject: |
|
|
It get now really time that you start to read the manual or helpfile.
Bascom != Qbasic.
Code: |
Temp = NOT Test1
If Temp =1 then
Set Test1
End If
|
_________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
RWo
Joined: 23 Sep 2015 Posts: 22
|
Posted: Mon Oct 19, 2015 8:59 pm Post subject: |
|
|
Hi,
Quote: | It get now really time that you start to read the manual or helpfile.
Bascom != Qbasic. |
here a sample:
Code: |
DIM a(3) AS INTEGER
a(1) = 0: a(2) = 0: a(3) = 0
IF NOT a(1) = 1 OR NOT a(2) = 1 THEN
a(3) = 1
END IF
PRINT a(3)
|
...use this in QB and run. Then let us know, what is the value of a(3)... |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Mon Oct 19, 2015 9:48 pm Post subject: |
|
|
Don't care what's in qbasic, this is the Bascom forum and in Bascom you can't do 2 thing's on the same line. See my previous post.
a+b+c=d works in qbasic, not in Bascom. It's all in the helpfile READ it and delete qbasic. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Tue Oct 20, 2015 11:51 pm Post subject: |
|
|
Quote: |
IF NOT a(1) = 1 OR NOT a(2) = 1 THEN
a(3) = 1
END IF
|
I could ask why you dont avoid the NOT entirely, and just write
Code: |
IF a(1) = 0 OR a(2) = 0 THEN
a(3) = 1
END IF
|
Saves using extra machine cycles to do the trivial and static calculation NOT (a) _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Wed Oct 21, 2015 8:22 am Post subject: |
|
|
It seems "NOT" in Bascom cannot be used as a logical NOT ( ! in C).
Rather it performs the bitwise NOT (~ in C).
Code: | Bascom example:
A = &b_00001111
B = NOT A ' B = &b_11110000
C example:
A = 0b00001111
B = ! A // B = 0
B = ~ A // B = 0b11110000 |
|
|
Back to top |
|
|
RWo
Joined: 23 Sep 2015 Posts: 22
|
Posted: Thu Oct 22, 2015 4:38 pm Post subject: |
|
|
Yes!
QB Help...
Code: | NOT Operator
Syntax
result = NOT numeric-expression
The logical-complement operator evaluates each bit in numeric-expression,
then sets the corresponding bit in the result according to the following
table:
-----------------------------------------
Bit in Expression Bit in Result
-----------------------------------------
1 0
0 1
-----------------------------------------
This inverts the bit values of any variable. If an integer variable has
the value 0 (false), the variable becomes -1 (true), and vice-versa.
|
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri Oct 23, 2015 7:57 am Post subject: OR NOT |
|
|
Did you get it OR NOT?
Simply had to do this...
Have a nice weekend all
Ben Zijlstra |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Oct 23, 2015 10:06 am Post subject: Re: OR NOT |
|
|
bzijlstra wrote: | Did you get it OR NOT? |
I'm all for creating the RATHERNOT operator.
Further I suggest to extend QB's syntax with the WHEREISMYHEAD, DAUOFTHEMONTH, and finally IAMAGENIUSANDNOBODYSEESTHAT operators. |
|
Back to top |
|
|
|