Click here to Skip to main content
15,885,546 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Power of 2 Pin
Cedric Moonen5-Mar-06 23:44
Cedric Moonen5-Mar-06 23:44 
GeneralRe: Power of 2 Pin
toxcct5-Mar-06 23:46
toxcct5-Mar-06 23:46 
GeneralRe: Power of 2 Pin
Stephen Hewitt5-Mar-06 23:45
Stephen Hewitt5-Mar-06 23:45 
GeneralRe: Power of 2 Pin
Stephen Hewitt6-Mar-06 2:04
Stephen Hewitt6-Mar-06 2:04 
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 
Read this function, it could be another start point!
This function that I wrote last year find the bigger long, greater than the input value, that is a power of 2.
And it is quite fast!Smile | :)
unsigned long Next2Power(unsigned long x){<br />
	unsigned long y=1, x1=x;<br />
	if(x==0) return 0;<br />
	while(x1!=0){<br />
		x1>>=1;<br />
		y<<=1;<br />
	}<br />
	y>>=1;<br />
	if(y!=x) y<<=1;<br />
	return y;<br />
}


Have a nice code day Wink | ;)


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 
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 

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.