?
Solved

Identity if an expression value is a power of 2 in a single C statement

Posted on 2005-04-06
2
Medium Priority
?
182 Views
Last Modified: 2010-04-15
Hi,

Ca someone please let me know how to identify if an expression value is a power of 2 in a single C statement ?

Rgds.
0
Comment
Question by:purinitin
2 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 13724397
Hi purinitin,

if ( (n & n-1) == 0 )
     printf ("power of two\n");

Cheers!
sunnycoder
0
 

Author Comment

by:purinitin
ID: 13724438
How about an alternate way ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question