You are using a binary coded decimal driver, right.
Do this:
//pins for bit 1 -4
short pins[] = {5,2,3,4}
int i, j;
//display numbers from 0-10
for(i = 0; i< 10; i++) {
// for each pin output the corresponding bits
for(j = 0; j <4; j++) {
digitalWrite(pins[j], (i >> j) & 1);
}
delay(5000);
}