Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > DATA STRUCTURES, C, C++, VC ++ > ds. c , c++ Interview / Technical Questions
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

ds. c , c++ Interview / Technical Questions Kindly solve an many as questions you can. It will sharpen your skills and those solutions will help others too.

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 23-01-07, 01:14 PM   #1 (permalink)
Moderator
 
GEEK's Avatar
 
Join Date: Nov 2006
Age: 25
Posts: 227
Thanks: 1
Thanked 12 Times in 9 Posts
Thanks: 1
Thanked 12 Times in 9 Posts
Rep Power: 6 GEEK is on a distinguished road GEEK is on a distinguished road
C language - How to write a C program to find the power of 2 in a normal way and in single step?

How to write a C program to find the power of 2 in a normal way and in single step?
GEEK is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-02-08, 09:38 PM   #2 (permalink)
Junior Member
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1 sands7788 is on a distinguished road
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?

Quote:
Originally Posted by GEEK View Post
How to write a C program to find the power of 2 in a normal way and in single step?
if((n&(n-1))==0)
printf("The number is a power of two");
Eg:
Consider 8
8---> 1000
7---> 0111
8&7-->0000
Therefore 8 is a power of 2!!
Consider 12
12---> 1100
11---> 1011
12&11-->1000
Therefore 12 is not a power of two
sands7788 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26-03-08, 05:50 PM   #3 (permalink)
Junior Member
 
Join Date: Apr 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2 query123 is on a distinguished road
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?

#include<math.h>

pow(2,i); // 2 raise to i......i can have any value
query123 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27-03-08, 01:30 PM   #4 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117
Thanked 241 Times in 198 Posts
Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Re: C language - How to write a C program to find the power of 2 in a normal way and in single step?

1<<n;

/* above statement is equal to 2 power n; you can change value of n to any value.
But keep in mind that this statement abilities are restricted by the size of integer.
So you can't try with too big value for n */

Thanks,
Krishna
__________________
Give 1 cup rice to a hungry Indian just by a mouse click. No money, no form filling, no hassle... Click here for the donation.
sk_kireeti is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +6.5. The time now is 12:39 PM.





Search Engine Optimization by vBSEO 3.1.0