-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteConverterClass.cs
63 lines (53 loc) · 1.74 KB
/
ByteConverterClass.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
namespace GrandiaStatEditor
{
public class ByteConverterClass
{
public static byte[] IntToByte(string value)
{
byte[] bytes = new byte[1];
Buffer.BlockCopy(BitConverter.GetBytes(int.Parse(value)), 0, bytes, 0, 1);
return bytes;
}
public static byte[] Int16ToBytes(string value)
{
byte[] bytes = new byte[2];
Buffer.BlockCopy(BitConverter.GetBytes(int.Parse(value)), 0, bytes, 0, 2);
return bytes;
}
public static byte[] Int32ToBytes(string value)
{
byte[] bytes = new byte[4];
Buffer.BlockCopy(BitConverter.GetBytes(int.Parse(value)), 0, bytes, 0, 2);
return bytes;
}
public static string AddZero(string value)
{
var result = int.Parse(value);
return result.ToString();
}
public static string AddFour(string value)
{
var result = int.Parse(value) + 4;
return result.ToString();
}
public static string AddSeven(string value)
{
var result = int.Parse(value) + 7;
return result.ToString();
}
public static int NibbleToByte(string nibble1, string nibble2)
{
var firstNibble = int.Parse(nibble1);
var SecondNibble = int.Parse(nibble2);
var result = (byte)(firstNibble << 4) | SecondNibble;
return result;
}
public static Tuple<byte, byte> GetNibble(byte value)
{
byte nibble1 = (byte)(value & 0x0F);
byte nibble2 = (byte)((value & 0xF0) >> 4);
return Tuple.Create(nibble2, nibble1);
}
}
}