forked from lllsondowlll/botw-trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteSwap.cs
41 lines (35 loc) · 1.22 KB
/
ByteSwap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace BotwTrainer
{
using System;
public static class ByteSwap
{
public static ushort Swap(ushort input)
{
if (BitConverter.IsLittleEndian)
{
return (ushort)(((0xFF00 & input) >> 8) | ((0x00FF & input) << 8));
}
return input;
}
public static uint Swap(uint input)
{
if (BitConverter.IsLittleEndian)
{
return ((0xFF000000 & input) >> 24) | ((0x00FF0000 & input) >> 8) | ((0x0000FF00 & input) << 8)
| ((0x000000FF & input) << 24);
}
return input;
}
public static ulong Swap(ulong input)
{
if (BitConverter.IsLittleEndian)
{
return ((0xFF00000000000000 & input) >> 56) | ((0x00FF000000000000 & input) >> 40)
| ((0x0000FF0000000000 & input) >> 24) | ((0x000000FF00000000 & input) >> 8)
| ((0x00000000FF000000 & input) << 8) | ((0x0000000000FF0000 & input) << 24)
| ((0x000000000000FF00 & input) << 40) | ((0x00000000000000FF & input) << 56);
}
return input;
}
}
}