Click here to Skip to main content
15,909,205 members
Home / Discussions / C#
   

C#

 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 14:13
sitebuilderLuc Pattyn29-Nov-07 14:13 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 10:55
sitebuilderLuc Pattyn29-Nov-07 10:55 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 12:38
mvePIEBALDconsult29-Nov-07 12:38 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 13:57
sitebuilderLuc Pattyn29-Nov-07 13:57 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 13:59
mvePIEBALDconsult29-Nov-07 13:59 
AnswerRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 6:02
mvePIEBALDconsult29-Nov-07 6:02 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 6:22
Skippums29-Nov-07 6:22 
AnswerRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 6:15
sitebuilderLuc Pattyn29-Nov-07 6:15 
Hi Jeff,

Skippums wrote:
Is there a better way to do this, like perhaps a binary search algorithm?


yes there is.

Seems you want the bit number of the most significant bit set.
Some CPUs have an instruction for this ("find first one" or "count leading zeroes").
Using it on x86 would mean P/Invoke to another dll (C/C++ with asm)

Without asm, the optimal approach depends on the application. So here are a few questions:

What is the range of integers you expect? (smaller range may yield faster code)
And what is the distribution? (to optimally order the operations)

final Q: is there any calculation involved in getting the input value (such as multiplying,
dividing, shifting)?

BTW: the Petes and Pauls of CP will tell you "wrong forum; try Math/Algo".

Smile | :)





Luc Pattyn [Forum Guidelines] [My Articles]


this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets


GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 6:30
Skippums29-Nov-07 6:30 
GeneralRe: Base 2 Log Method Pin
Ennis Ray Lynch, Jr.29-Nov-07 6:36
Ennis Ray Lynch, Jr.29-Nov-07 6:36 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 8:58
mvePIEBALDconsult29-Nov-07 8:58 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 9:22
sitebuilderLuc Pattyn29-Nov-07 9:22 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 9:41
Skippums29-Nov-07 9:41 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 10:12
mvePIEBALDconsult29-Nov-07 10:12 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 10:14
sitebuilderLuc Pattyn29-Nov-07 10:14 
Questionfeatures of .net Pin
George Mathew29-Nov-07 4:56
George Mathew29-Nov-07 4:56 
AnswerRe: features of .net Pin
Rob Philpott29-Nov-07 5:04
Rob Philpott29-Nov-07 5:04 
AnswerRe: features of .net Pin
J4amieC29-Nov-07 5:04
J4amieC29-Nov-07 5:04 
AnswerRe: features of .net Pin
Judah Gabriel Himango29-Nov-07 5:06
sponsorJudah Gabriel Himango29-Nov-07 5:06 
GeneralRe: features of .net Pin
led mike29-Nov-07 5:08
led mike29-Nov-07 5:08 
AnswerDO YOUR OWN HOMEWORK Pin
leckey29-Nov-07 5:41
leckey29-Nov-07 5:41 
AnswerRe: features of .net Pin
PIEBALDconsult29-Nov-07 6:05
mvePIEBALDconsult29-Nov-07 6:05 
AnswerThe problem Pin
Ennis Ray Lynch, Jr.29-Nov-07 6:38
Ennis Ray Lynch, Jr.29-Nov-07 6:38 
AnswerRe: features of .net Pin
Justin Perez29-Nov-07 7:33
Justin Perez29-Nov-07 7:33 
AnswerRe: features of .net Pin
Vasudevan Deepak Kumar29-Nov-07 7:41
Vasudevan Deepak Kumar29-Nov-07 7:41 

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.