Author Topic: Question about bitwise and logical and operator  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Question about bitwise and logical and operator
« on: November 12, 2018, 03:42:35 AM »
Hi Charles,

I do not know much about logical and bitwise operators, so I am not sure how to interpret my results. I tried this little code:

Code: [Select]
int r1,r2,r3,r4,r5,r6
int a=60, b=13
 
r1 = (a and b)    'bitwise and
r2 = (a & b)      'bitwise and

r3 = (60 && 13)   'Logical and

r4 = (a&b)        'addition?

r5 = (a& b)    'bitwise and
r6 = (a &b)    'address?

print r1 ", " r2 ", " r3 ", " r4 ", " r5 ", " r6

r4 seems to be an addition and r6 seems to point to an address. Are these the expected results?

Roland
« Last Edit: November 12, 2018, 06:25:15 AM by Arnold »

Charles Pegge

  • Guest
Re: Question about bitwise and logical and operator
« Reply #1 on: November 12, 2018, 08:15:16 AM »
Hi Roland,

Very interesting.

What the compiler sees in the case of r4:

r4 = (a&  b)

the '&' is seen as a suffix of a, like a$, which is stripped off.

r4 = (a  b)

Since '+' is the default operator, this is interpreted as:

r4 = (a+b)

&b is interpreted as an address in r6

The & symbol does too many things :)

Arnold

  • Guest
Re: Question about bitwise and logical and operator
« Reply #2 on: November 12, 2018, 09:23:12 AM »
Thank you Charles. I would normaly use (a and b), yet in this case I copied a formula coded in C and forgot to do this. But now I understand what happened.

Charles Pegge

  • Guest
Re: Question about bitwise and logical and operator
« Reply #3 on: November 12, 2018, 01:59:18 PM »
Perhaps I should alter the behaviour of r6.