码迷,mamicode.com
首页 > Web开发 > 详细

【.NET】大小端互转,反转字节序

时间:2020-12-17 12:57:32      阅读:3      评论:0      收藏:0      [点我收藏+]

标签:字节   rgb   div   nbsp   turn   reverse   ever   static   ffffff   

代码已测试

public static long Reverse(long value)
{
    return (((long)Reverse((int)value) & 0xFFFFFFFF) << 32)
            | ((long)Reverse((int)(value >> 32)) & 0xFFFFFFFF);
}

public static ulong Reverse(ulong value)
{
    return (((ulong)Reverse((uint)value) & 0xFFFFFFFF) << 32)
            | ((ulong)Reverse((uint)(value >> 32)) & 0xFFFFFFFF);
}

public static int Reverse(int value)
{
    return (((int)Reverse((short)value) & 0xFFFF) << 16)
            | ((int)Reverse((short)(value >> 16)) & 0xFFFF);
}

public static uint Reverse(uint value)
{
    return (((uint)Reverse((ushort)value) & 0xFFFF) << 16)
            | ((uint)Reverse((ushort)(value >> 16)) & 0xFFFF);
}

public static short Reverse(short value)
{
    return (short)((((int)value & 0xFF) << 8) | (int)((value >> 8) & 0xFF));
}

public static ushort Reverse(ushort value)
{
    return (ushort)((((int)value & 0xFF) << 8) | (int)((value >> 8) & 0xFF));
}

 

【.NET】大小端互转,反转字节序

标签:字节   rgb   div   nbsp   turn   reverse   ever   static   ffffff   

原文地址:https://www.cnblogs.com/crsky/p/14125316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!