I am using a mcp23017 to read button presses for my joystick project and am using the internal pullup to minimize complications. Is there a way to invert all the bits in the uint16_t so i can send the values as normally off?

I'm using this Adafruit library.

And the reading code: uint16_t buttons = mcp.readGPIOAB();

1 Answer 1


The inversion operator in C++ is ~.

Serial.print(buttons, BIN);
Serial.print(~buttons, BIN);
  • Amazing dude thanks!!! I added a ~ in front of mcp.digitalReadGPIOAB(); and that has done the trick.
    – user862
    Commented Mar 29, 2014 at 21:42
  • 1
    Welcome to Arduino! You can click the "accept" button (the green checkmark by the answer) to mark that this solution worked. Thanks! :) Commented Mar 29, 2014 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.