C# Byte数组有符号无符号转换及对应表

对应表:

 

 

 

1 规约规定

 

 对应代码解法

 public static decimal FindValue(int dataType, byte[] temps)
        {
            if (dataType == 1)
            {
                return (sbyte)temps[0];
            }
            else if (dataType == 2)
            {
                return temps[0];
            }
            else if (dataType == 3)
            {
                short aa = BitConverter.ToInt16(temps, 0);
                return aa;
            }
            else if (dataType == 4)
            {
                ushort aa = BitConverter.ToUInt16(temps, 0);
                return aa;
            }
            else if (dataType == 5)
            {
                int aa = BitConverter.ToInt32(temps, 0);
                return aa;
            }
            else if (dataType == 6)
            {

                uint aa = BitConverter.ToUInt32(temps, 0);
                return aa;
            }
            else if (dataType == 7)
            {

                long aa = BitConverter.ToInt64(temps, 0);
                return aa;
                //valueLength = 8;
            }
            else if (dataType == 8)
            {

                ulong aa = BitConverter.ToUInt64(temps, 0);
                return aa;
            }
            else if (dataType == 9)
            {

                float aa = BitConverter.ToSingle(temps, 0);
                return (decimal)aa;
            }
            else if (dataType == 10)
            {

                double aa = BitConverter.ToDouble(temps, 0);
                return (decimal)aa;
            }

 

posted @ 2020-08-31 11:31  zklve2  阅读(3026)  评论(0编辑  收藏  举报