Inverting Shift Register outputs in Arduino IDE.

So finally i hooked up a 74HC595 Shift Register, to a 7 Segment display, but it is a common Anode type, i hooked it up like normal LEDs and used the following code to display the letter "A":

int dataPin = 2;        //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;



void setup()
{
    pinMode(dataPin, OUTPUT);       //Configure each IO Pin
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
}

void loop()
{
    
        digitalWrite(latchPin, LOW);          //Pull latch LOW to start sending data
        shiftOut(dataPin, clockPin, MSBFIRST, 0x11 );         //Send the data
        digitalWrite(latchPin, HIGH);         //Pull latch HIGH to stop sending data
       delay (1000);

As you can see Hex 0x11 means 00010001, i had to invert in manually, is there anyway i can do it in software, ie the 0's will become 1's and vice versa.

Use the bitwise invert operator: ~ (tilde)

shiftOut(dataPin, clockPin, MSBFIRST, ~data ); //Send the data, inverted

It doesnt seem to work :~

Maybe my question isnt clear i mean to say if a byte is: 10101010

I want it to be: 01010101

Cross posted. (in Displays).

Pete

adilmalik:
Maybe my question isnt clear i mean to say if a byte is: 10101010

I want it to be: 01010101

That's what the '~' operator does. Perhaps you have some other error.

Read my answer in your crosspost in "Displays".

Pete