Click here to Skip to main content
15,892,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Power of 2 Pin
toxcct6-Mar-06 2:06
toxcct6-Mar-06 2:06 
AnswerRe: Power of 2 Pin
Russell'5-Mar-06 23:33
Russell'5-Mar-06 23:33 
GeneralRe: Power of 2 Pin
RichardS5-Mar-06 23:38
RichardS5-Mar-06 23:38 
GeneralRe: Power of 2 Pin
Russell'6-Mar-06 0:11
Russell'6-Mar-06 0:11 
QuestionRe: Power of 2 Pin
David Crow6-Mar-06 2:54
David Crow6-Mar-06 2:54 
AnswerRe: Power of 2 Pin
Russell'6-Mar-06 4:02
Russell'6-Mar-06 4:02 
GeneralRe: Power of 2 Pin
David Crow6-Mar-06 5:04
David Crow6-Mar-06 5:04 
AnswerRe: Power of 2 Pin
Divyang Mithaiwala5-Mar-06 23:45
Divyang Mithaiwala5-Mar-06 23:45 
Hello RichardS,

Try this one.

double val = 0.0;
val = log10(y) / log10(2.0);

//Check that 'val' is pure int (Here you use ur own code is u optimize)
int val2 = int(val);

if (val == val2) 
     // y is power of 2
else
     // y is not power of 2


here 'y' is value u want to check for power of 2.

Best of luck


Divyang Mithaiwala
System Engineer & Software Developer
GeneralRe: Power of 2 Pin
toxcct5-Mar-06 23:47
toxcct5-Mar-06 23:47 
GeneralRe: Power of 2 Pin
Divyang Mithaiwala6-Mar-06 0:25
Divyang Mithaiwala6-Mar-06 0:25 
GeneralRe: Power of 2 Pin
toxcct6-Mar-06 0:28
toxcct6-Mar-06 0:28 
GeneralRe: Power of 2 Pin
Divyang Mithaiwala5-Mar-06 23:51
Divyang Mithaiwala5-Mar-06 23:51 
AnswerRe: Power of 2 Pin
BadKarma5-Mar-06 23:51
BadKarma5-Mar-06 23:51 
AnswerRe: Power of 2 Pin
Taka Muraoka5-Mar-06 23:53
Taka Muraoka5-Mar-06 23:53 
GeneralRe: Power of 2 Pin
Ryan Binns6-Mar-06 0:15
Ryan Binns6-Mar-06 0:15 
AnswerRe: Power of 2 Pin
Ryan Binns5-Mar-06 23:59
Ryan Binns5-Mar-06 23:59 
GeneralRe: Power of 2 Pin
Stephen Hewitt6-Mar-06 0:13
Stephen Hewitt6-Mar-06 0:13 
GeneralRe: Power of 2 Pin
Ryan Binns6-Mar-06 0:16
Ryan Binns6-Mar-06 0:16 
GeneralRe: Power of 2 Pin
Stephen Hewitt6-Mar-06 0:18
Stephen Hewitt6-Mar-06 0:18 
GeneralRe: Power of 2 Pin
Ryan Binns6-Mar-06 0:19
Ryan Binns6-Mar-06 0:19 
GeneralRe: Power of 2 Pin
Stephen Hewitt6-Mar-06 0:22
Stephen Hewitt6-Mar-06 0:22 
GeneralRe: Power of 2 Pin
Ryan Binns6-Mar-06 0:23
Ryan Binns6-Mar-06 0:23 
GeneralRe: Power of 2 Pin
Nibu babu thomas6-Mar-06 0:15
Nibu babu thomas6-Mar-06 0:15 
GeneralRe: Power of 2 Pin
Ryan Binns6-Mar-06 0:17
Ryan Binns6-Mar-06 0:17 
GeneralRe: Power of 2 Pin
Nibu babu thomas6-Mar-06 0:18
Nibu babu thomas6-Mar-06 0:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.