Let me see if I understand. You want to convert a pair of TTL signals from a rotary encoder that swing between 0V and 5V (TTL levels) into a pair of signals that swing between 0V and 24V at a frequency of 1 MHz.
The last requirement eliminates the use of a comparator like the LM339 or LM393. A modern comparator with an open collector output might be a candidate but I don't have a part number in mind. The idea would be to run the output from the encoder to one input, and use a voltage divider on the other input to set the threshold. The output would need a pullup resistor to +24V. The comparator will need a pretty big slew rate to keep up with a 1 MHz. signal.
Second choice would be a single transistor inverting level shifter. This would be a common emitter switch. You need to make sure that you pull the base up to +5V when the TTL output is high since a TTL gate will not source muuch current. When the TTL gate goes low it will sink plenty of current.