I have byte[] srno in my code
byte[] srno = new byte[6];
srno[0] = 0xff;
srno[1] = 0x0f;
srno[2] = 0x24;
srno[3] = 0x12;
srno[4] = 0x16;
srno[5] = 0x0a;
now I want this value in uint like
uint a = 0xff0f2412160a;
How to convert it?
As @animaonline suggested, you should use BitConverter
to convert byte array to uint or *ulong. Thus you have 6 bytes, uint is too small for you. You should convert to ulong*. But converter requires eight bytes, so create new array with required number of bytes:
byte[] value = new byte[8];
Array.Reverse(srno); // otherwise you will have a1612240fff result
Array.Copy(srno, value, 6);
ulong result = BitConverter.ToUInt64(value, 0);
Console.WriteLine("{0:x}", result); // ff0f2412160a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With