Added swappers for reference values.

This commit is contained in:
2017-07-15 01:29:26 +01:00
parent 43b05214d6
commit 1380e1c94f

View File

@@ -29,6 +29,8 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2017 Natalia Portillo
// ****************************************************************************/
using System;
using System.Linq;
namespace DiscImageChef
{
@@ -99,5 +101,40 @@ namespace DiscImageChef
{
return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
}
public static ulong Swap(ulong x)
{
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
return x;
}
public static long Swap(long x)
{
return BitConverter.ToInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0);
}
public static ushort Swap(ushort x)
{
return (ushort)((x << 8) | (x >> 8));
}
public static short Swap(short x)
{
return (short)((x << 8) | ((x >> 8) & 0xFF));
}
public static uint Swap(uint x)
{
x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF);
return (x << 16) | (x >> 16);
}
public static int Swap(int x)
{
x = (int)(((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF));
return (x << 16) | ((x >> 16) & 0xFFFF);
}
}
}