Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

...need some help to Logical operators NOT OR

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
RWo

Bascom Member



Joined: 23 Sep 2015
Posts: 22

blank.gif
PostPosted: Mon Oct 19, 2015 1:58 pm    Post subject: ...need some help to Logical operators NOT OR Reply with quote

...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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Mon Oct 19, 2015 7:26 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
RWo

Bascom Member



Joined: 23 Sep 2015
Posts: 22

blank.gif
PostPosted: Mon Oct 19, 2015 8:59 pm    Post subject: Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Mon Oct 19, 2015 9:48 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue Oct 20, 2015 11:51 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Wed Oct 21, 2015 8:22 am    Post subject: Reply with quote

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
View user's profile
RWo

Bascom Member



Joined: 23 Sep 2015
Posts: 22

blank.gif
PostPosted: Thu Oct 22, 2015 4:38 pm    Post subject: Reply with quote

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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Oct 23, 2015 7:57 am    Post subject: OR NOT Reply with quote

Did you get it OR NOT?

Simply had to do this...
Have a nice weekend all

Ben Zijlstra
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Oct 23, 2015 10:06 am    Post subject: Re: OR NOT Reply with quote

bzijlstra wrote:
Did you get it OR NOT?

I'm all for creating the RATHERNOT operator. Very Happy
Further I suggest to extend QB's syntax with the WHEREISMYHEAD, DAUOFTHEMONTH, and finally IAMAGENIUSANDNOBODYSEESTHAT operators.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum