Page 1 of 1
bitwise and fails ?
Posted: 22 Aug 2019 07:30
by plouf
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
Re: bitwise and fails ?
Posted: 22 Aug 2019 09:32
by hexreader
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.
Re: bitwise and fails ?
Posted: 22 Aug 2019 13:02
by plouf
crap.. you are right !
was confusing and with +