-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFunctions.cs
69 lines (63 loc) · 2.05 KB
/
Functions.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
64
65
66
67
68
69
using OpenTK;
using System;
public class Functions
{
public static byte[] ConvertShortArraytoByteArray(short[] shorts)
{
byte[] bytes = new byte[shorts.Length * 2];
for (int i = 0; i < shorts.Length; i++)
{
bytes[i * 2] = (byte)(shorts[i] >> 8);
bytes[i * 2 + 1] = (byte)(shorts[i] & 0xFF);
}
return bytes;
}
public static Int64[] ConvertByteArrayToInt64(byte[] bytes)
{
Int64[] Bits64 = new Int64[bytes.Length / 8];
for (int i = 1; i < Bits64.Length; i++)
{
int Bytesidx = i * 8;
Bits64[i] = bytes[Bytesidx + 7] << 56;
Bits64[i] |= bytes[Bytesidx + 6] << 48;
Bits64[i] |= bytes[Bytesidx + 5] << 40;
Bits64[i] |= bytes[Bytesidx + 4] << 32;
Bits64[i] |= bytes[Bytesidx + 3] << 24;
Bits64[i] |= bytes[Bytesidx + 2] << 16;
Bits64[i] |= bytes[Bytesidx + 1] << 8;
Bits64[i] |= bytes[Bytesidx];
}
return Bits64;
}
public static Int64[] ConvertShortArrayToInt64(short[] shorts)
{
Int64[] Bits64 = new Int64[shorts.Length / 4];
for (int i = 1; i < Bits64.Length; i++)
{
int Shortsidx = i * 4;
Bits64[i] = shorts[Shortsidx + 3] << 48;
Bits64[i] |= shorts[Shortsidx + 2] << 32;
Bits64[i] |= shorts[Shortsidx + 1] << 16;
Bits64[i] |= shorts[Shortsidx];
}
return Bits64;
}
public static void Copy64BitsToArray(Int64[] SrcArray, int SrcOffset, Int64[] DstArray, int DstOffset, int size)
{
for (int i = 0; i < size; i++)
{
DstArray[DstOffset + i] = SrcArray[SrcOffset + i];
}
}
public static void CopyBytes(byte[] SrcArray, int SrcOffset, byte[] DstArray, int DstOffset, int size)
{
for (int i = 0; i < size; i++)
{
DstArray[DstOffset + i] = SrcArray[SrcOffset + i];
}
}
public byte readByte(byte[] bytes, int offset)
{
return bytes[offset];
}
}