Live data from Hacker News

Ten Ways to Check if an Integer Is a Power Of Two in C

exploringbinary.com

11–20 of 82 posts

Re: Ten Ways to Check if an Integer Is a Power Of Two in C

#11
post #6
post #4

Earlier quoted context omitted.

[deleted]

Because the methods clearly get more complicated. Starting simply and naively and then improving is a perfectly standard way of teaching. Articles like these, which provide detailed explanation of the methods involved and results of benchmarks help greatly.

[deleted]

Re: Ten Ways to Check if an Integer Is a Power Of Two in C

#17
post #6
post #4

Earlier quoted context omitted.

[deleted]

Because the methods clearly get more complicated. Starting simply and naively and then improving is a perfectly standard way of teaching. Articles like these, which provide detailed explanation of the methods involved and results of benchmarks help greatly.

The benchmarks would probably be somewhat misleading in a lot of cases here. I'm fairly certain that most compilers will replace a /2 with >>1 for example, so that isn't really going to end up being reflected when you compile it.
Post reply on HN