Conversion of byte array containing hex values to decimal values

前端 未结 5 2033
一生所求
一生所求 2021-01-01 04:17

I am making application in c#.Here i want to convert a byte array containing hex values to decimal values.Suppose i have one byte array as

array[0]=0X4E;
ar         


        
5条回答
  •  萌比男神i
    2021-01-01 04:57

    Instead of checking IsLittleEndian by yourself, you can use IPAddress.NetworkToHostOrder(value).

    int value = BitConverter.ToInt32(array, 0);
    
    value = IPAddress.NetworkToHostOrder(value);
    

    See more:

    https://docs.microsoft.com/de-de/dotnet/api/system.net.ipaddress.networktohostorder?redirectedfrom=MSDN&view=netframework-4.7.2#System_Net_IPAddress_NetworkToHostOrder_System_Int32_

提交回复
热议问题