To get the current state of a pin, we need to read the contents of the PORTA and PORTB registers. We do this by simply accessing the variable 'PORTA' or 'PORTB'. This is the same register that we've been using to control our outputs, the behaviour of each of it's pins is determined by the contents of the respective TRISA/B register bit.

In order to check the state of an individual pin in the register, we use the '&' operation, which performs a logical AND operation between it and the value on the right. For more information on this have a look at the 'Working on bits' page.

We then use the result of this in a condition. Remember that the condition will read true if the value in the brackets comes out non-zero, so we can check the states of other bits on the port by simply changing the value on the right of the '&' sign.