My code isn't lighting segments it needs to just random segments

I’m trying to write a code that counts 0-9 and a-f with button presses but it doesn’t seem to activate any segments and other times it lights random segments. i’m not sure what I’m missing any help you can give me would be appreciated. trying to do it without the use of shiftOut

const int latchPin = 7; // Pin connected to Pin 7 of 74HC595 (Latch)
const int dataPin = 4; // Pin connected to Pin 4 of 74HC595 (Data)
const int clockPin = 8; // Pin connected to Pin 8 of 74HC595 (Clock)
int button = 13; // pushbutton attached to pin 13
int currentState = 1; // initialise currentState as HIGH
int previousState = 0;
int counter = 0; // initialise counter as zero
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
bool b;
int number_array[16] = // 0-9 A-F
{
B11111100,//0
B01100000,//1
B11011010,//2
B11110010,//3
B01100110,//4
B10110110,//5
B10111110,//6
B11100000,//7
B11111110,//8
B11100110,//9
B11101110,//A
B00111110,//B
B10011100,//C
B01111010,//D
B10011110,//E
B10001110,//F
};

void setup(){
pinMode(latchPin, OUTPUT); // set SR pins to output
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(button, INPUT); // sets pin 12 as pushbutton INPUT pinMode(downPin, INPUT); // sets pin 13 as pushbutton INPUT
b=true;
}
void loop(){
currentState = digitalRead(button);
if (previousState != currentState){
previousState = currentState;
if (currentState == HIGH)
counter++;
}

if(counter < 0)
counter++;
writeToShiftRegister(number_array[counter]);
if(counter == 16) {counter = 0;}
}

void writeToShiftRegister (byte value){
unsigned char count;
unsigned char j;
j=0;
while (j<10){
if(b != digitalRead(button)) {
for(count = 0; count<20 && b != digitalRead(button); count++);
b=((count>=20 && b!=digitalRead(button))?!b:b);
if (!b) {j++;}}
switch(j){
case 0:return B11111100;break;//0
case 1:return B01100000;break;//1
case 2:return B11011010;break;//2
case 3:return B11110010;break;//3
case 4:return B01100110;break;//4
case 5:return B10110110;break;//5
case 6:return B10111110;break;//6
case 7:return B11100000;break;//7
case 8:return B11111110;break;//8
case 9:return B11100110;break;//9
case 10:return B11101110;break;//A
case 11:return B00111110;break;//B
case 12:return B10011100;break;//C
case 13:return B01111010;break;//D
case 14:return B10011110;break;//E
case 15:return B10001110;break;//F
default:return B00000000;break;
}
delay(50);
}
}

for(count = 0; count<20 && b != digitalRead(button); count++);

 switch(j){
          case 0:return B11111100;break;//0
          case 1:return B01100000;break;//1
          case 2:return B11011010;break;//2
          case 3:return B11110010;break;//3
          case 4:return B01100110;break;//4
          case 5:return B10110110;break;//5
          case 6:return B10111110;break;//6
          case 7:return B11100000;break;//7
          case 8:return B11111110;break;//8
          case 9:return B11100110;break;//9
          case 10:return B11101110;break;//A
          case 11:return B00111110;break;//B
          case 12:return B10011100;break;//C
          case 13:return B01111010;break;//D
          case 14:return B10011110;break;//E
          case 15:return B10001110;break;//F
          default:return B00000000;break;

Two quick notes. If you have a return, then you don’t need the break. Nothing ever needs to come after a return.

And why do you have this big switch statement to return these binary values? You already have those values in an array. Why not replace all this with just.

return number_array[j];

PS: next time you post code, please use code tags instead of quote tags. [code]  code goes here [/code]

You can use the </> button on the reply window to generate them or type them yourself.