Transforming compass direction output

I have directional outputs which are both flipped and + – as appose to genuine compass outputs. I want to convert these using math to give me the correct output. I am pretty sure this can be done …