performance - fast binary digit counter 64bits numbers c# -
I try to find out its solution everywhere
For example:
127 = 7 binary digits 153 = 8 binary numbers
I got it in two ways to get it.
- By triming binary representation in a string, and using the "lamps" property.
- By obtaining the greatest power of 2, which does not pass the number, the result is that binary is the last place of representation, and if you add 1, then points to the number of points (which is 2 ^ 0)
Both ways are good, but it takes too much time to calculate when the numbers are larger than 10.000.000.000 (10 billion) after you spent in seconds Calculate the time, which is the milliseconds Instead of Kands, and so bad for the performance of the rest of the code.
Thank you very much and sorry Presentation, it has been written with a phone and I do not have all the tools to keep this fanatic and correct.
Edit 1
Consider deeply the website of Bithax and see the speed as the first priority. I think I am going to use the method with implementation.
As I found: There should be something like that with Lookup Table 2 ^ 6 for 64bits.
Fixed ReDonline Int [] MultiplyBrowsNationPit2 = New Int [64] (0,1,2,4,8,17,34,5,11,23,47,31,63, 62,61,59, 55,46,29, 58,53,43,22,44,24,49,35,7,15,30,60,57, 51,38,12,25,50,36, 9,18,37,10,21,42,20,41,19,39,14,28,56,48,33,3,6,13,27,54,45,26,52,40,16, 32};
And based on this, the user creates "R." StackerVerf Flow, making itself that there should be something like this in C #:
Interactive> Static Interlock 2_DeBruijn (Ullong v) {Return multiplyDeBruijnBitPosition2 [(UlhoneG) (v * 0x022fdd63cc95386dull)>> 58];}
The result is really fast but Gul And I do not know exactly why. PD: As you can see for "0x022fdd63cc95386dull" 128bits, the accepted code for C # is "0x022fdd63cc95386d" It looks like that appears in the lookup tables.
I think because I can not use "0x022fdd63cc95386dull" in C #, I have to use another number instead of 58, or maybe a whole hexadecimal 64 bit multiplier.
So far, for the input number: 17012389719861204799 (64 bits have been used)
- Using the Pau 2 method, I have received the result in 1380ms 1 million times.
- Using the debugged method, I get 32 mms as a result of 40 millimeters. According to (you do not know why 40)
It can:
UIT V; UITT R; UIT changes; R = (uint) ((v> 0xFFFF) 1: 0) & lt; & Lt; 4; V> & Gt; = (Int) r; Shift = (uint) ((v> 0xFF) 1: 0) & lt; & Lt; 3; V> & Gt; = Shift (int); R | = Shift; Shift = (UIT) ((V> 0xF) 1: 0) & lt; & Lt; 2; V> & Gt; = Shift (int); R | = Shift; Shift = (UIT) ((V> 0x3) 1: 0) & lt; & Lt; 1; V> & Gt; = Shift (int); R | = Shift; R | = (V & gt; & gt; 1); // The result on this point R is
Comments
Post a Comment