A magnetic field sensor (10′) of a system for measuring speed and direction of rotation of a rotary shaft, measuring values (A, K) of the magnetic field generated by the passage of the teeth (T1, T2 . . . Ti) of a toothed wheel associated with said rotary shaft, called target (14), in front of said sensor (10) and delivering a signal (S, S′, S″) to processing means (13), said signal (S, S′, S″) comprising pulses (I) between a high state and a low state, each pulse (I) being representative of the passage of a tooth (T1, T2 . . . Ti) in front of the sensor (10′), and each pulse (I) having two predetermined durations, a first duration (t1) representative of a first direction of rotation of the target (14), and a second duration (t2) representative of the opposite direction of rotation of the target (14),
- wherein said sensor (10) comprises:
- storage means (30) for predetermined threshold values (Aref, Kref) of the magnetic field (B, B′, B″),
- comparison means (31) between the measured values (A, K) of the magnetic field (B, B′, B″) and the predetermined threshold values (Aref, Kref) of the magnetic field (B, B′, B″),
- means (32) for generating at least one third predetermined pulse duration (t3) and at least one fourth predetermined pulse duration (t4), to produce a binary coding of the signal (S′, S″), representative of the measured values (A, K) of the magnetic field (B, B′, B″), intended for the processing means (13).