That is XOR.
0^0=0
0^1=1
1^0=1
1^1=0
If Polarity is 1 or 0, depending on user settings. If Polarity is 0 then bit isn't inverted and result is same as:
mosfet_gate = 0 ; Turn ON
mosfet_gate = 1 ; Turn OFF
If Polarity is 1 then then bit are inverted so result is
mosfet_gate = 1 ; Turn ON
mosfet_gate = 0 ; Turn OFF