Here is a demo program:
LIST
100 POKE 5891,255
200 POKE 5890,0
300 POKE 5889,0
400 D=PEEK(5888)
500 B=0
600 FOR I=0 TO 7
700 BIT = (D AND (2^I)) / (2^I)
800 IF BIT=0 THEN B=B+(2^I)
900 NEXT I
1000 POKE 5890,B
1100 GOTO 400
OK
Because the KB doesn't have an XOR operand, we need to do it manually. The speed is a bit slow, and the LED will respond after 1.5 to 2 seconds.
If you don't mind the reversed switches, you can just poke the value to PB, which will be faster.
Liu