title: Flip one random bit in integer
body: <p>I would like to flip one bit in integer. So I have to convert integer to binary, than flip one random bit and than convert it back to integer. How could i do that?</p>
  <pre><code># what I want to get:
  # num = 8 ... 1000
  # new_num = flip_one_bit(num)
  # it flips one random bit in 1000 -&gt; 0000 or 1010 or 1100, ...
  # returns back it's decimal value 0000 = 0; 1010 = 10
  from random import randint
  
  def flip_one_bit(num: int) -&gt; int:
      b_num = bin(num)
      # flip one bit than convert back to integer
      return b_num
  </code></pre>
  <p>Side question: Is there any way to convert binary to integer without building my own function (anything built-in)? What's the &quot;good way&quot; of doing this?</p>