Bitbanging replace characters in function

Doing things that have to happen at intervals of less than 2 µsecs is going to be difficult with a 16MHz Arduino.

Are you planning to run your program directly on an ESP8266 or on an Arduino connected to an ESP8266 ?

I have not yet tried programming an ESP8266.

For those data rates on a 16MHz Arduino you would need direct port manipulation rather than use digitalWrite(). Even then it may not be possible to operate at the required rate.

...R