
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 0.90 KB | hits: 12 | expires: Never
Can Mono DataConvert be used to read a 3-byte integer?
public Region(string regionFile)
{
var conv = DataConverter.BigEndian;
var chunks = new Chunk[Chunk.MaxLocations];
using (var fs = File.OpenRead(regionFile))
{
var buffer = new byte[4096];
fs.Read(buffer, 0, buffer.Length);
// Read chunk locations
for (int i = 0; i < Chunk.MaxLocations; ++i)
{
chunks[i] = new Chunk(conv.ToInt24(buffer, i * 4), buffer[i * 4 + 3]);
}
}
}
public override int GetInt24(byte[] data, int index)
{
if (data == null)
throw new ArgumentNullException("data");
if (data.Length - index < 3)
throw new ArgumentException("index");
if (index < 0)
throw new ArgumentException("index");
int ret = 0;
byte* b = (byte*)&ret;
for (int i = 0; i < 3; i++)
b[2 - i] = data[index + i];
return ret;
}