Controlling 18 LEDs via 3 shift-registers

I’m currently making a Tic-tac-toe board, and have some issues getting the LEDs to light up the way I want. I’ve got three shift-registers connected in cascade, and I’m planning on controlling which led is on/off via a 18bit bitmask. I’ve tried to extend the shiftOut function to take in a long instead of a byte, and bitwise-and 18 bits instead of the normal 8. With some debugging via serial monitor it seems like when I try to shift out 0x3FFFF it shifts out “001111111111111111”, which according to my calculations should be “111111111111111111”.

void shiftOut(int myDataPin, int myClockPin, long myDataOut) {
	//Shifts out 18 bits to board

  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  for (i=17; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    //if the value passed to myDataOut and a bitmask result 
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000 
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else {	
      pinState= 0;
    }

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin  
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
    Serial.print(pinState);
  }
  //stop shifting
  digitalWrite(myClockPin, 0);
  Serial.println();
}

Am I completely on the wrong track on how to solve this, or am I missing something obvious?

I can't see you doing anything with the latch pin.

void loop() {

    //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, 0);
    //move 'em out
    shiftOut(dataPin, clockPin, 0x3FFFF);  
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(300);
 }

Forgot to add my loop, here you go.

shiftme.ino (2.15 KB)

Figured out the problem, I forgot to add an L to force my bitshifted bit to be counted as a long.

Changing this:

    if ( myDataOut & (1<<i) ) {

to this:

    if ( myDataOut & (1L<<i) ) {

made everything function as expected.