Click here to Skip to main content
15,898,628 members
Home / Discussions / C#
   

C#

 
GeneralRe: Strange frequency readings Pin
Luc Pattyn29-Nov-07 11:16
sitebuilderLuc Pattyn29-Nov-07 11:16 
GeneralRe: Strange frequency readings Pin
Big Daddy Farang29-Nov-07 12:26
Big Daddy Farang29-Nov-07 12:26 
Questionclickonce error Pin
arkiboys29-Nov-07 6:58
arkiboys29-Nov-07 6:58 
QuestionLINQ to SQL Question Pin
Philip Laureano29-Nov-07 5:38
Philip Laureano29-Nov-07 5:38 
GeneralRe: LINQ to SQL Question Pin
Sam Xavier18-Jan-08 0:02
Sam Xavier18-Jan-08 0:02 
QuestionBase 2 Log Method Pin
Skippums29-Nov-07 5:26
Skippums29-Nov-07 5:26 
AnswerRe: Base 2 Log Method Pin
led mike29-Nov-07 5:35
led mike29-Nov-07 5:35 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 6:13
Skippums29-Nov-07 6:13 
For example, the following code, which takes the middle bit of a bound (0 to 32), and attempts to perform the right shift. If the result is 0, I shifted the number too far, so I make my new range 0 to 16, take the new average (8), and try again. If the number is greater than 1 at that point, you modify the lower bound, so now I am shifting 12 bits (average of 8 and 16). Continue this cycle until you find the magic number that makes the resulting shift equal to 1. This is O(log(n)) time, vs. my initial algorithm of O(n). I did some testing of the two, and the second is far faster for randomly generated numbers, but only because most randomly generated are large. When I set the upper bound to 0x1000 (4096) on the random number size, the two algorithms broke even, taking about .95 s to do 0x1000000 (16,777,216) log base 2 method calls. The code is below...

private byte Log2_2(uint val) {
    if (val < 1)
        return byte.MaxValue;
    byte high = sizeof(uint) << 3;
    byte low  = 0, med = (byte)(high >> 1);
    uint tmp = val >> med;
    while (tmp != 1) {
        if (tmp == 0)
            high = med;
        else
            low  = med;
        med = (byte)(low + high >> 1);
        tmp = val >> med;
    }
    return med;
}


Jeff
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 7:46
sitebuilderLuc Pattyn29-Nov-07 7:46 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 8:12
Skippums29-Nov-07 8:12 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 8:39
sitebuilderLuc Pattyn29-Nov-07 8:39 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 8:59
Skippums29-Nov-07 8:59 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 9:18
sitebuilderLuc Pattyn29-Nov-07 9:18 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 9:37
Skippums29-Nov-07 9:37 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 9:56
sitebuilderLuc Pattyn29-Nov-07 9:56 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 10:19
mvePIEBALDconsult29-Nov-07 10:19 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 10:36
sitebuilderLuc Pattyn29-Nov-07 10:36 
JokeRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 13:06
mvePIEBALDconsult29-Nov-07 13:06 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 13:23
sitebuilderLuc Pattyn29-Nov-07 13:23 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 13:43
mvePIEBALDconsult29-Nov-07 13:43 
GeneralRe: Base 2 Log Method Pin
Luc Pattyn29-Nov-07 14:02
sitebuilderLuc Pattyn29-Nov-07 14:02 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 10:26
mvePIEBALDconsult29-Nov-07 10:26 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 10:45
Skippums29-Nov-07 10:45 
GeneralRe: Base 2 Log Method Pin
PIEBALDconsult29-Nov-07 13:03
mvePIEBALDconsult29-Nov-07 13:03 
GeneralRe: Base 2 Log Method Pin
Skippums29-Nov-07 13:21
Skippums29-Nov-07 13:21 

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.