-
Notifications
You must be signed in to change notification settings - Fork 16
/
BinaryReaderBE.cs
52 lines (45 loc) · 1.21 KB
/
BinaryReaderBE.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
using System.IO;
using System.Text;
public class BinaryReaderBE : BinaryReader
{
public BinaryReaderBE(Stream stream, Encoding encoding) : base(stream, encoding) { }
public BinaryReaderBE(Stream stream) : base(stream) { }
public override short ReadInt16()
{
byte byte1 = ReadByte();
byte byte2 = ReadByte();
return (short) (byte1 << 8 | byte2);
}
public override ushort ReadUInt16()
{
byte byte1 = ReadByte();
byte byte2 = ReadByte();
return (ushort) (byte1 << 8 | byte2);
}
public override int ReadInt32()
{
byte byte1 = ReadByte();
byte byte2 = ReadByte();
byte byte3 = ReadByte();
byte byte4 = ReadByte();
return (int) ((byte1 << 24) | (byte2 << 16) | (byte3 << 8) | (byte4));
}
public override uint ReadUInt32()
{
byte byte1 = ReadByte();
byte byte2 = ReadByte();
byte byte3 = ReadByte();
byte byte4 = ReadByte();
return (uint) ((byte1 << 24) | (byte2 << 16) | (byte3 << 8) | (byte4));
}
public double ReadFixed() {
int i = ReadInt32();
return (double) i / 65536.0;
}
public string ReadMacString(int length)
{
byte[] bytes = ReadBytes(length);
Encoding macRoman = Encoding.GetEncoding(10000);
return macRoman.GetString(bytes).Split(new char[] {'\0'})[0];
}
}