Usually the public exponent is first chosen. Often it is the 4th prime of Fermat (e.g.
openssl), 65537. This number in binary is:
0000 0000 0000 0000 0001 0000 0000 0000 0001
Fermat primes are primes with just 2 bits set. 3, 5, 17, 257 and 65537 are the only known Fermat primes. It is relatively easy to use this as exponent as only two bits are set. This makes the exponentiation rather fast.
After that the primes $p$ and $q$ are chosen in such a way that they comply with the chosen public key. To be precise, this means that $p - 1$ and $q - 1$ need to be relative prime to $e$. This is slightly different than most text book methods of generating an RSA key pair where $p$ and $q$ are chosen first.
Smaller and much larger exponents may be vulnerable to some kind of attacks. Usually other properties for which the keys are used - mainly padding - cause these attacks to be impossible. Cryptographers and standardization institutes however like to play it safe, so current implementations almost unanimously choose the fourth prime of Fermat as public exponent.
Choosing a high valued public exponent will hurt performance because higher values will take more time during the modular exponentiation used for encryption and verification. If $e$ is randomized then it is usually 16 bit value at most (e.g. original implementations of PGP).