How do I create a 9 bit number based on values from 9 digital inputs?
In your code you would use a 16 bit unsigned integer as your variable. As there is no such thing as a 9 bit type. 

If the pins correspond to different ports on your micro, you basically do this:

Read the pin value from the port register, and bit shift to the right bit position then OR with the variable.

Say you had 8 of the LEDS on PORTB (pin 0 - 7 )and the 9th on PORTC (pin 2)

unsigned int ir_inputs = 0

ir_inputs = PORTB; //just reads the register directly
ir_inputs = ir_inputs|((PORTC &amp; 0x04)&lt;&lt;6); //reads the bit on pin 2 then shifts it 6 places to bit 8 (or the 9th bit remember bits always start at 0) and does not affect the other bits


something like that

actually you could put it into a function

unsigned int getIRinputs(void){
    return (unsigned int)PORTB|((PORTC &amp; 0x04)&lt;&lt;6);
}


Easy done

Even if you had the inputs on 9 separate ports the principle is the same.
Read, Shift, OR