I need to find the smallest power of two that's greater or equal to a given value. So far, I have this:  int value = 3221; // 3221 is just an example, could be any number int result = 1;  while (result &lt; value) result &lt;&lt;= 1;   It works fine, but feels kind of naive. Is there a better algorithm for that problem?  EDIT. There were some nice Assembler suggestions, so I'm adding those tags to the question.
I want to write a function that returns the nearest next power of 2 number. For example if my input is 789, the output should be 1024. Is there any way of achieving this without using any loops but just using some bitwise operators?
Search using symbols is broken "If" and "Whether" - Is interrogative IF always replacable by WHETHER? I am asking here specifically about if and whether  when they introduce embedded questions (or to be more technically accurate, subordinate interrogative clauses):  I don't know if Bob's here. I don't know whether Bob's here.  In the sentence above we can freely replace if with whether. There are some situations in which the reverse does not apply. We cannot always replace whether with if. For example in standard English, we cannot normally use if after a preposition:  The question of whether he is actually eligible didn't arise. *The question of if he is actually eligible didn't arise.  We cannot usually use interrogative-if directly followed by or not:  It's unclear whether or not he's a real elephant. *It's unclear if or not he's a real elephant.  There are several more examples. However, what I want to know is:  Are there any examples where we can use interrogative-if but we can't use whether?   Edit note: There is an if that we find in conditionals that can't be replaced by whether. However, this is conditional, not interrogative, if. When light waves enter a medium of higher refractive index than the previous, why is it that:  Its wavelength decreases? The frequency of it has to stay the same? Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error Connect to Linux by name rather than IP Niven’s theorem proof. I couldn’t find any proof on the internet. I would appreciate an elementary proof , but any help would be appreciated!  Thank you. I have seen somewhere that classical distances (like Euclidean distance) become weakly discriminant when we have multidimensional and sparse data. Why? Do you have an example of two sparse data vectors where the Euclidean distance does not perform well? In this case which similarity should we use? 10 hour layover in Moscow Russia, do I need a transit visa? On June 29th 2015, I will be traveling for the first time to Italy from USA. I will have a 10 hour layover in Moscow Russia. My question is, do I need a visa to visit the city? We roll a die until each side appears at least once, then we stop.     What is the probability of rolling exactly $n$ dice?   I guess the answer is  $$6-6\left(\dfrac{5}{6}\right)^n\;,$$  but this may be wrong.  In trying to solve this problem, I read , but I couldn't solve the problem. How would one be able to prove mathematically that $1+1 = 2$? Is it possible to prove that $1+1 = 2$? Or rather, how would one prove this algebraically or mathematically? Will yearly moderation statistics be published on all sites this year, and future years? What is the easiest way to update/upgrade an offline Ubuntu machine with the help of a Windows machine that has internet access?  This question also applies to installing new packages offline and not only updates/upgrades.  The Linux system shall remain completely cut off from the Windows machine, meaning there should be no ethernet connection or the likes between the two computers.  Update:  Please have patience, since I haven't updated this since two weeks. There are some complications getting apt-offline to work properly on Lubuntu and all other methods seem to be too old and deprecated:  AptOff - last update 2006 AptMedium - last update 2007 Keryx - last update 2011, looks like this project was discontinued  I hope I will be able to somehow update the offline machine, finally.  While I was still not able to update/upgrade the offline system due to authentication errors, I accepted an answer, because it's taking too long. How to move apps from internal to external storage? Is it always possible to find the limit of a function without using  or ?  For example,   $$\lim_{x\to0}\frac{\tan x-x}{x^3}$$  $$\lim_{x\to0}\frac{\sin x-x}{x^3}$$  $$\lim_{x\to0}\frac{\ln(1+x)-x}{x^2}$$  $$\lim_{x\to0}\frac{e^x-x-1}{x^2}$$  $$\lim_{x\to0}\frac{\sin^{-1}x-x}{x^3}$$  $$\lim_{x\to0}\frac{\tan^{-1}x-x}{x^3}$$ How do we pass the field api name in lwc for a lightning data table? Calling the base constructor in C# If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?  For example, if I inherit from the Exception class I want to do something like this:  class MyExceptionClass : Exception {      public MyExceptionClass(string message, string extraInfo)      {          //This is where it's all falling apart          base(message);      } }   Basically what I want is to be able to pass the string message to the base Exception class. So I was writing up a simple binary tree in Python and came across [...]  I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm completely lost to, however   &gt;&gt;&gt; a [[[[[], [], 8, 3], [[], [], 3, 2], 6, 3], [], 1, 4], [[], [], -4, 2], 0, 0] &gt;&gt;&gt; Keys(a)#With a+b [0, 1, 6, 8, 3, -4] &gt;&gt;&gt; Keys(a)#With [a,b] [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]] &gt;&gt;&gt; Keys(a)[1]#?? [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...], 8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]]     Version using a+b  def Keys(x,y=[]):     if len(x):y+=[x[2]]+Keys(x[0],y)+Keys(x[1],y)#Though it seems I was using y=y[:]+, this actually outputs an ugly mess     return y   version using [a,b]  def Keys(x,y=[]):     if len(x):y+=[x[2],Keys(x[0],y),Keys(x[1],y)]     return y   So what exactly is [...]? How to find out which (not installed) Debian package a file belongs to? On Debian systems (and derivatives):  $ dpkg --search /bin/ls coreutils: /bin/ls   That is, the file /bin/ls belongs to the Debian package named coreutils.  But this only works if the package is installed. What if it's not? Let $p$ be a prime. Suppose that $\gcd(a, b) = p$. Find $\gcd(a^2,b)$ for all integers $a$ and $b$. Let $p$ be a prime. Suppose that $\gcd(a, b) = p$. Find $\gcd(a^2,b)$  for all integers a and b.   I was able to prove that $\gcd(a^2,b^2) = p$ but I don't know if it helps.  Any help is greatly appreciated. I created a interior scene and  i don't know how to bake a texture using cycles bake.