c# - Best way to read single byte from array of bytes -


i have array of bytes , want read bytes 1 one , convert int. getting date in byte of array need create datatime object that. using following code. should best approach same performance perspective.

byte[] date = {25, 10, 13, 04, 16, 26} //day month year hour minute second  capturetime = new datetime(                         (int)(new arraysegment<byte>(date, 2, 1).toarray()[0]), // year                         (int)(new arraysegment<byte>(date, 1, 1).toarray()[0]), // month                         (int)(new arraysegment<byte>(date, 0, 1).toarray()[0]), // day                         (int)(new arraysegment<byte>(date, 3, 1).toarray()[0]), //hours                         (int)(new arraysegment<byte>(date, 4, 1).toarray()[0]), //minutes                         (int)(new arraysegment<byte>(date, 5, 1).toarray()[0])); //seconds 

above code working fine performance point of view fine or there more approach handle this?

byte 8-bit unsigned integer implicitly upcast int when needed.

maybe i'm under-thinking things, what's wrong obvious , efficient:

byte[] octets = {25, 10, 13, 04, 16, 26} //day month year hour minute second  datetime date = new datetime(                   2000 + octets[2] , // year                          octets[1] , // month                          octets[0] , // day                          octets[3] , // hour                          octets[4] , // minutes                          octets[5]   // seconds                 ) ; console.writeline( "the date is: {0:f}" , date ) ; 

which produces expected:

the date is: friday, october 25, 2013 4:16:26 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -