shifting a bit with strange results

Hi,
I'm trying to work with a shift register so as part of the learning curve I wanted to make sure I can activate all the output pins on the shift register.
I take a variable and inside a loop shift it the number 1 buy the number of steps of the loop.
This works fine from 0 to 6 but when I get to 7 I get a strange output

i is: 7
Display1 is: 11111111111111111111111110000000

The code I'm using is:

// hardware constants
int LEDClockPin = 12;  // Arduino Pin #12 - 4094 Pin 3 clock
int LEDDataPin = 11;   // Arduino Pin #11  - 4094 pin 2 Data
int LEDStrobePin = 10; // Arduino Pin # 10  - 4094 pin 1 Strobe 

char Display1=0;

void setup()
{
  // initialise the hardware	
  // initialize the appropriate pins as outputs:
  pinMode(LEDClockPin, OUTPUT); 
  pinMode(LEDDataPin, OUTPUT); 
  pinMode(LEDStrobePin, OUTPUT); 
   
  Serial.begin(19200);   // setup the serial port to 9600 baud
}

void loop()
{
  Display1 = 0;  
 for (int i=0;i< 8; i++)
    {
      Display1 = (1<<i);     
     digitalWrite(LEDStrobePin,LOW); 
     shiftOut(LEDDataPin, LEDClockPin, MSBFIRST,Display1);
      Serial.print("i is: ");
      Serial.println(i,DEC);
      Serial.print("Display 1 is: ");
      Serial.println(Display1,BIN);
      digitalWrite(LEDStrobePin,HIGH);
      delay(1000);
      
    }
}

Would appreciate any advice on what I'm doing wrong.
Thanks

It's an artifact of the fact that with a 1 in the left-most bit (MSB) the number is considered negative.

You could try making Display1 byte type, rather than char.

Yep, forgot about that little tidbit of using signed variables.

Changed it to byte and unsigned int and both works.

Thanks guys :slight_smile: