Magnetically coded sensor