C#中将16/32位无符号十进制数转换成16进制字节数组

        /// 
        /// 将一个16位无符号十进制数 高低位分离
        /// 
        /// 
        /// 
        public static byte[] DecSplit(ushort DecValue)
        {
            byte[] ByteVal = new byte[2];
            ByteVal[0] = (byte)((DecValue >> 8) & 0xff);     //高八位
            ByteVal[1] = (byte)(DecValue & 0xff);            //低八位
            return ByteVal;
        }
        /// 
        /// 将一个32位无符号十进制数 每8位分离
        /// 
        /// 
        /// 
        public static byte[] DecSplit(uint DecValue)
        {          
            byte[] ByteVal = new byte[4];
            ByteVal[0] = (byte)((DecValue >> 24) & 0xff);
            ByteVal[1] = (byte)((DecValue >> 16) & 0xff);
            ByteVal[2] = (byte)((DecValue >> 8) & 0xff);     
            ByteVal[3] = (byte)(DecValue & 0xff);
            return ByteVal;
        }

你可能感兴趣的:(工控上位机C#,c#,算法)