bitwise and fails ?

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
plouf
Posts: 27
Joined: 16 Jan 2015 09:34
Location: Athens,Greece

bitwise and fails ?

#1 Post by plouf » 22 Aug 2019 07:30

HI
whats wrong with this

the temp4 should be %11111111 but variable is remain 0 in simulator

Code: Select all

dim tempi as integer
dim temp2 as byte
dim temp3 as byte
dim temp4 as byte

main:
temp2 = %10101010
temp3 = %01010101

temp4 = temp2 and temp3
simulator shot
https://imge.to/i/mgg1r
Christos

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: bitwise and fails ?

#2 Post by hexreader » 22 Aug 2019 09:32

I think you are confusing "and" with "or"

Zero is correct for "and"

You would only get %11111111 if you "or" the two

To see the result in simulation you may need at least one more instruction after the calculation.

Maybe something like:

Code: Select all

' found on forum...
' simple logic test program
' processor unknown, clock speed unknown
' mikroBASIC compiler 7.2.0

program forum

' Declarations section 
    dim tempi as integer
    dim temp2 as byte
    dim temp3 as byte
    dim temp4 as byte

    main:
    temp2 = %10101010                           ' test value 1
    temp3 = %01010101                           ' test value 2

    temp4 = temp2 or temp3                      ' expect 0 for "and" or %11111111 for "or"

    temp2 = 0                                   ' pointless instruction just to allow result to be seen in simulator
    
    while 1                                     ' infinite loop at end
    wend
end.
Start every day with a smile...... (get it over with) :)

plouf
Posts: 27
Joined: 16 Jan 2015 09:34
Location: Athens,Greece

Re: bitwise and fails ?

#3 Post by plouf » 22 Aug 2019 13:02

crap.. you are right !
was confusing and with +
Christos

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”