FYI, on the 4 wire O2 harness,
The two white wires are the O2 sensor heater wires. Polarity is unimportant on these white wires.
The black wire is the O2 sensor voltage output signal wire. This is the signal that goes to the ECU.
The grey wire is a secondary ground. The O2 sensor is already grounded to the exhaust pipe by being screwed into the sensor bung hole. Best to ground the grey wire to the chassis instead of the exhaust pipe.
Ignoir the main wire harness color codes. The main harness/O2 sensor connector plug design will keep the wires clocked correctly .......provided you match a 3 wire O2 sensor to a 3 wire main harness.
I've never actually done it before but I'm sure the ECU would be fried if battery voltage (12V) was accidently applied to the O2 voltage signal wire (in the main wire harness) leading TO the ECU. The O2 sensor generates only 1.1 volts max. (and a few milliamps). 12 volts (and hundreds of amps) applied to that circuit might turn that ECU circuit to toast.
There's plenty of text in the archived threads about buying a 3 wire (2 white wire, 1 black wire) O2 sensor for a '87-'92 Ford Mustang and using it in the E30 BMW's. The Bosch sensor probe itself is identical between the Ford and BMW. The difference being the wire harness connector AND about 100 bucks! The BMW sensor lists for ~$135. The Ford Mustang sensor lists for ~$38.95 at Auto Zone. Aren't we Bimmer owners special?
Cut the old BMW O2 sensor harness pigtail close to the sensor. Cut the Mustang O2 sensor harness pigtail close to the connector plug. Splice the two pigtail harness : white wires together (polarity unimportant) Remember, these are only sensor heater wires.
Now splice the single black wires together. The black wire is the O2 voltage signal that goes to the ECU. Insulate all splices.
Now, you have a spliced O2 pigtail harness with a new O2 sensor on one end and the old BMW wire harness connector on the other end and insulated wire splices somewhere in the middle. It's probably about 4-5' long! That's a bit long. Shorted it to about the same length as the original BMW sensor harness pigtail. You get the picture (and save a C Note).