What is the best way to read a 24 bit unsigned integer from a C # stream using BinaryReader?
So far I have used something like this:
private long ReadUInt24(this BinaryReader reader)
{
try
{
return Math.Abs((reader.ReadByte() & 0xFF) * 256 * 256 + (reader.ReadByte() & 0xFF) * 256 + (reader.ReadByte() & 0xFF));
}
catch
{
return 0;
}
}
Is there a better way to do this?
source
share