-->
Page 1 of 1

Use of HEX with a variable and the XOR function

PostPosted: Wed Aug 17, 2016 9:43 am
by Ecoli-557
I get an error on the following and I don't understand why. Could someone enhance my learning?
Code: Select allOutPin = hex(ThisPin xor 255) 'this should return a hex value of the inverted value

I am working on code to exercise a MCP23S17 port expander and I want a way to invert the logic as there is no way to directly address the port by individual bit as you can in Arduino.

Any direction would be useful.
Regards to All.

Re: Use of HEX with a variable and the XOR function

PostPosted: Wed Aug 17, 2016 4:21 pm
by Mmiscool
Encapsulate the xor evaluation in its own set of parenthesizes.

Code: Select allOutPin = hex((ThisPin xor 255))

Re: Use of HEX with a variable and the XOR function

PostPosted: Wed Aug 17, 2016 4:31 pm
by Ecoli-557
Yup, your Da Man!
That works for my MCP23S17 demo. DOn't know why though. I don't see the reason for double (()) around the same function.
Why does this work
Code: Select allOutPin = hex((ThisPin xor 255))

and not this
Code: Select allOutPin = hex(ThisPin xor 255)

Re: Use of HEX with a variable and the XOR function

PostPosted: Wed Aug 17, 2016 4:38 pm
by Ecoli-557
Yup, your Da Man!
That works for my MCP23S17 demo. DOn't know why though. I don't see the reason for double (()) around the same function.
Why does this work
Code: Select allOutPin = hex((ThisPin xor 255))

and not this
Code: Select allOutPin = hex(ThisPin xor 255)