For which values of $p$ can you simulate a $p$-biased coin using a fair coin in a fixed number of tosses (the "reverse" direction of this problem)?
I have read of an approach where you consider the binary expansion of $p$, let's call it $0.b_1b_2b_3\dots$. Then, we toss the fair coin until it lands on heads. Let's say this took $n$ tosses. If $b_n=1$, then we map this to a heads for our $p$-biased coin, otherwise if $b_n=0$ we map this to a tails. This works because the probability of mapping to heads in our $p$-biased coin is simply $$\sum_{i|b_i=1}\frac{1}{2^i}=0.b_1b_2b_3\dots=p$$
But this still gives an expected run time of $2$ flips. Is there an approach which takes a constant worst case number of flips? Or is the binary representation of $p$ in base 2 terminating a necessary condition for this to be the case? Any ideas are appreciated!