C# int to byte[] int 转 byte[]

 private static byte[] int2bytes(Int16 intValue)
        {
            byte[] intBytes = BitConverter.GetBytes(intValue);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(intBytes);
            byte[] result = intBytes;
            return result;
        }

返回一个2位的byte

 private static byte[] int2bytes(Int32 intValue)
        {
            byte[] intBytes = BitConverter.GetBytes(intValue);
            if (BitConverter.IsLittleEndian)
                Array.Reverse(intBytes);
            byte[] result = intBytes;
            return result;
        }

返回一个4位的byte

posted on 2020-01-02 11:02  马什么梅  阅读(1892)  评论(0编辑  收藏  举报

导航