c# - Refactor for Speed: Convert To a Date -


I work for myself, I am calling in a self-employed encode and as a result I reviewed the code Is not luxury or the ability to improve on the basis of peer programming

  internal fixed date time CONVERT_To_DateTime (integer binDate) {// 3, I use it as an exercise to see For the StackOverflow community, there is a simple way for which I I am going to be able to review the review / 10/2008 = 182255615 9 // 2008/02/10 = 18225233 9 1/2008/01/10 = 18224 9 0623 // 30/09/2008 = 18223 9 231 9/29 / 09/2008 = 182235 9 551 // September 30th 2008 // +18223 9 231 9 = 0x6c9f7fff // 0x6c = 108 = 2008 (based on the date 1900 starting date) // 0x9 = 9 = September // 0xf7fff - take top 5 bit = 0x1e = 30 // 1st October 2008 // 18224 9 0623 = 0x6ca0ffff // 0 x6c = 108 = 2008 // 0 Xa = 10 = Oct // 0x0ffff - take top 5 bit = 0x01 = 1 // binary (used by this function Goes) // one = +1822556159 (200 8/03/10) // 1,101,100 1010 using 00011111111111111111 / b = 1822523391 (2/10/2008) // 1101100 1010 00010 111111111111111 // c = 1822490623 (2008/01/10) // 1,101,100 1010 00001 111111111111111 // D = 18223 9 231 9 (30/09/2008) // 1,101,100 1001 11110 111111111111111 // Additional 111111 is probably used for the time / seconds which // We currently do not care for var in BaseYear = 1 9 00; // binary var strbinary = Dump to long date to convert. Toasting; // year var calculation of strBYear = strBinary.Substring (0, 7); Var iYear = Convert toInt32 (strByear, 2) + basware; // month var strBMonth = calculation of strBinary.Substring (7, 4); Var iMonth = Convert toInt32 (strBMonth, 2); // day var strBDay = strBinary.Substring (11, 5) calculation; Var iDay = Convert toInt32 (strBDay, 2); // Make sure that there are two digits of the month and day var strday = iDay & lt; 10? "0" + Id: IDA. Toasting (); Var strMonth = iMonth & lt; 10? "0" + iMonth: iMonth.ToString (); // change the last date var = changed iyear + strmonth + strday; Return date time Purse axt (converted, "yyyammed", blank); }  

This is a method that represents a numerical date and changes it into datetime datatype. I want to do The method is to achieve the fastest possible execution time as it is being implemented within a loop to be reviewed.

As any comment on the method it will be an exercise for me Is appreciated. I look forward to some reactions.

You are manipulating the string, it is the perfect performance killer when used in tight ends.

  Fixed date time toDateTime (int value) {var year = (int) ((value & amp; 0xff000000)> 24); Var months = (value & amp; 0xf00000) & gt; & Gt; 20; Var day = (value & amp; (0xf8000)) & gt; & Gt; 15; New date time back (1900+ year, month, day); }  

Here's how you do this.

This is a mask for the year:

FF 0 0 0 0

This month's Is for:

  0 f 0 0 0 0 0  

And this is for the day:

  0 "Code"> "year" value is correct  6 * 4  bits, "month" -  5 * 4  

/ Code>, and "days" - should be transferred to 3 * 4 + 3 bits.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -