Second-kill quick configuration with a super-large binary integer

Source: Internet
Author: User
Using System; using System. collections. generic; using System. linq; using System. text; using System. numerics; using System. globalization; using System. diagnostics; namespace ConsoleApplication11 {class Program {static int [] howmustics = new int,,, 2 ,,,, 7, 4, 5, 6, 6, 6, 6, 7, 5, 6, 7, 7, 8}; static void Main (string [] args) {Stopwatch SW = New Stopwatch (); SW. start (); BigInteger B = new BigInteger (234235436457658); BigInteger A = (BigInteger. one <3999) + B; Tuple <int, int> Sim = MatchDegree (A, B); SW. stop (); Console. writeLine ("Same number" + Sim. item1); Console. writeLine ("Total" + B. toByteArray (). length * 8); Console. writeLine ("offset" + Sim. item2); Console. writeLine ("milliseconds" + SW. elapsedMilliseconds); Console. read ();} public static Tuple <int, Int> MatchDegree (BigInteger A, BigInteger B) {Tuple <int, int> max = new Tuple <int, int> (0, 0); int a =. toByteArray (). length; B = B <a; int offset = 0; while (B> BigInteger. one) {B >>= 1; offset ++; int count = MatchDegree (~ (A ^ B); if (count> max. item1) {max = new Tuple <int, int> (count, offset) ;}return max ;}public static int MatchDegree (BigInteger A) {byte [] B =. toByteArray (); int count = 0; for (int I = 0; I <B. length; I ++) {count + = howmuw.[ B [I];} return count ;} // determine the number of public static int MatchDegree (ulong u) {u = (u & 0x5555555555555555) + (u> 1) in a ulong number) & 0x5555555555555555); u = (u & 0x3333333333333333) + (u> 2) & 0x3333333333333333); u = (u & 0x0f0f0f0f0f) + (u> 4) & 0x0f0f0f0f0f0f); u = (u & 0x00FF00FF00FF00FF) + (u> 8) & 0x00FF00FF00FF00FF); u = (u & 0x0000FFFF0000FFFF) + (u> 16) & 0x0000FFFF0000FFFF); u = (u & 0x000000000000ffffffff) + (u> 32) & 0x00000000FFFFFFFF); return Convert. toInt32 (u);} private static string DisplayInBinary (BigInteger number) {byte [] bytes = number. toByteArray (); string binaryString = string. empty; foreach (byte byteValue in bytes) {string byteString = Convert. toString (byteValue, 2 ). trim (); binaryString + = byteString. insert (0, new string ('0', 8-byteString. length) ;}return binaryString ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.