title: Round up a value to the nearest power of 2 in MySQL query
body: <p>I would like to round up a value to the next nearest power of 2 in a mysql query, so </p>
  
  <pre><code>select RoundUpToNearestPowerOfTwo(700) -- Should give 1024
  </code></pre>
  
  <p>I need this solution as part of a much larger query to generate and read some bitmask. Using custom stored functions is not an option, since I cannot use those in our production environment, so I'm looking for a smart way to do this inline in the query.</p>
  
  <p>[Edit]
  One possible way I can think of, is creating some enumerator, use a power in that, and choose the smallest value larger than my value:</p>
  
  <pre><code>  select
      min(BOUND)
    from
      (select 700 as VALUE) v
      inner join
        (select
          POW(2, @pow := @pow + 1) as BOUND
        from
          (select @pow := 0) x,
          MY_RANDOM_TABLE t
        ) x on x.BOUND &gt; v.VALUE
  </code></pre>
  
  <p>But as you can tell, it's pretty verbose, so a leaner solution would be welcome.            </p>