Usually this job is performed by a comparator, such as the LM393. If you have a 5V supply, for example, and your input signal can have any potential between 0V and 5V, then you must provide a "reference" potential for the comparator to compare against, to produce a digital high (+5V) or low (0V) output depending on which is higher, the reference or the input signal. This might be your circuit:
simulate this circuit – Schematic created using CircuitLab
Here I use R2 and R3 as a resistor potential divider to produce about +3.4V at node REF. This is the potential that the comparator treats as the switching threshold. When the input at IN rises above +3.4V, the comparator output goes high to +5V (with the help of R1, necessary due to the comparator's open-collector output). When the input potential falls below +3.4V, that output goes low.
C1 is optional, but recommended, to help keep REF steady in spite of power supply noise.
To find values for R2 and R3, use the following formula for the potential at REF:
$$ V_{REF} = V_{SUPPLY}\frac{R_3}{R_2+R_3} $$
In the above example this is:
$$ V_{REF} = +5V \times \frac{22k\Omega}{10k\Omega + 22k\Omega} = +3.4V $$
Comparators usually have some input hysteresis built in (a millivolt or so), which prevents the output from ever settling in between high and low, like an analogue amplifier might do, increase noise immunity, and to increase the transition speed of the output. It is this hysteresis which defines the comparator's output as "digital" in nature. Without hysteresis, it would be nothing more than a very high gain op-amp.
Hysteresis can be produced/increased by adding a small amount of positive feedback, which will be necessary if you use an ordinary op-amp in the role of comparator. Here I use the OPA990, with (exaggerated) positive feedback to produce similar behaviour to a real comparator:
simulate this circuit
R4 and R5 provide the positive feedback I mentioned, causing the switching threshold to shift depending on the current output state. This is what we call hysteresis. The two switching thresholds can be seen below, marked in green. The input is a sinusoid (but it could be any signal you care to provide), in blue, and the output is a clear digital +5V or 0V, in orange:
The hysteresis "gap" can be reduced by increasing R5, and vice versa. This technique would also work with a proper comparator, if you required more input hysteresis than the tiny amount already present.