How to write code to read Digital input from Handshake signals

Hi all,
in my task, I am responsible to read the position of a moving sensor that I have currently. There are 15 total positions that the sensor will move to. Variable Y02, Y03, Y04 and Y05 will determine the position of the sensor.

For example at position 2, the value for
Y02 = 0
Y03 = 1
Y04 = 0
Y05 = 0
The binary bit will be 0100. Every position has its own binary bit. How do I make program for the PLC to save that, when the binary is at 0100, it is at Position 2. Thank you in advance.

Best regards,
Umair

You can use the simple operator “.”, for instance wToto.2 is a boolean variable that reflect the state of the third bit of wToto.
In the util.lib you will find also useful bit/byte functions.
You can use EXTRACT function to select a specific bit of a BYTE or WORD.
You can also use WORD_AS_BIT to extract necessary bit of a WORD.