mirror of
https://github.com/aaru-dps/Aaru.Helpers.git
synced 2025-12-16 19:24:35 +00:00
[Aaru.Helpers] Reformat and cleanup.
This commit is contained in:
28
Swapping.cs
28
Swapping.cs
@@ -41,25 +41,25 @@ public static class Swapping
|
||||
/// <param name="x">Little endian unsigned integer</param>
|
||||
/// <returns>PDP unsigned integer</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16);
|
||||
public static uint PDPFromLittleEndian(uint x) => (x & 0xffff) << 16 | (x & 0xffff0000) >> 16;
|
||||
|
||||
/// <summary>Gets the PDP endian equivalent of the given big endian unsigned integer</summary>
|
||||
/// <param name="x">Big endian unsigned integer</param>
|
||||
/// <returns>PDP unsigned integer</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8);
|
||||
public static uint PDPFromBigEndian(uint x) => (x & 0xff00ff) << 8 | (x & 0xff00ff00) >> 8;
|
||||
|
||||
/// <summary>Swaps the endian of the specified unsigned short integer</summary>
|
||||
/// <param name="x">Unsigned short integer</param>
|
||||
/// <returns>Swapped unsigned short integer</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8));
|
||||
public static ushort Swap(ushort x) => (ushort)(x << 8 | x >> 8);
|
||||
|
||||
/// <summary>Swaps the endian of the specified signed short integer</summary>
|
||||
/// <param name="x">Signed short integer</param>
|
||||
/// <returns>Swapped signed short integer</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF));
|
||||
public static short Swap(short x) => (short)(x << 8 | x >> 8 & 0xFF);
|
||||
|
||||
/// <summary>Swaps the endian of the specified unsigned integer</summary>
|
||||
/// <param name="x">Unsigned integer</param>
|
||||
@@ -67,9 +67,9 @@ public static class Swapping
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint Swap(uint x)
|
||||
{
|
||||
x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF);
|
||||
x = x << 8 & 0xFF00FF00 | x >> 8 & 0xFF00FF;
|
||||
|
||||
return (x << 16) | (x >> 16);
|
||||
return x << 16 | x >> 16;
|
||||
}
|
||||
|
||||
/// <summary>Swaps the endian of the specified signed integer</summary>
|
||||
@@ -78,9 +78,9 @@ public static class Swapping
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Swap(int x)
|
||||
{
|
||||
x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF));
|
||||
x = (int)(x << 8 & 0xFF00FF00 | (uint)x >> 8 & 0xFF00FF);
|
||||
|
||||
return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF));
|
||||
return (int)((uint)x << 16 | (uint)x >> 16 & 0xFFFF);
|
||||
}
|
||||
|
||||
/// <summary>Swaps the endian of the specified unsigned long integer</summary>
|
||||
@@ -89,9 +89,9 @@ public static class Swapping
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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);
|
||||
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
|
||||
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
|
||||
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
|
||||
|
||||
return x;
|
||||
}
|
||||
@@ -102,9 +102,9 @@ public static class Swapping
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static long Swap(long x)
|
||||
{
|
||||
x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
||||
x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
||||
x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
||||
x = (x & 0x00000000FFFFFFFF) << 32 | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32);
|
||||
x = (x & 0x0000FFFF0000FFFF) << 16 | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16);
|
||||
x = (x & 0x00FF00FF00FF00FF) << 8 | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user