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;
            }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM