How are Mode 2 pulses encoded?
I think the problem is that you see a Mode 3/A (identity) reply, but you try to interpret it as Mode C (altitude reply). 

In Mode C, altitude is Gillham encoded, using all pulses except for D1 and X. This gives a range of -1200 to 126700 ft in 100 ft increments. 
If you see a D1 pulse, you are not looking at a Mode C reply. 

In Mode A, a 12 bit identity (squawk code) is transmitted, using all pulses except for X. In Mode A, the D1 pulse is commonly used (in fact, evey squawk code where the last digit is odd uses the D1 pulse).  It is simply the octal conversion of bits / pulses [A4 A2 A1], [B4 B2 B1], [C4 C2 C1], [D4, D2 D1].

For example, if you would encode squawk code 2345 you would set pulses [A2 = 2], [B1 &amp; B2 = 3], [C4 = 4] and [D4 &amp; D1 = 5]. 

Note that in case of Mode A, there may be an addition pulse for radar IDENTificaton. This is the Special Purpose Identification (SPI) pulse and it occurs 4.35 microseconds after the start of the closing framing pulse, with a duration of 0.45 microseconds.



source: www.radartutorials.eu