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

0 Members and 1 Guest are viewing this topic.

#### Arnold

• Hero Member
• Posts: 977
##### 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,r6int a=60, b=13 r1 = (a and b)    'bitwise andr2 = (a & b)      'bitwise andr3 = (60 && 13)   'Logical andr4 = (a&b)        'addition?r5 = (a& b)    'bitwise andr6 = (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

• Posts: 4486
##### 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

• Hero Member
• Posts: 977
##### 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.