Reputation: 77
I have a file. I've readed 3 bytes from offset 05. So how can I convert that byte[] to int24? Or if I convert that array to int32 and then convert that int32 to int24, it will work? And how to convert?
Upvotes: 3
Views: 1475
Reputation: 70746
Int24 isn't directly supported, however there is a similar question that describes how to achieve what you need:
public struct UInt24 {
private Byte _b0;
private Byte _b1;
private Byte _b2;
public UInt24(UInt32 value) {
_b0 = (byte)(value & 0xFF);
_b1 = (byte)(value >> 8);
_b2 = (byte)(value >> 16);
}
public unsafe Byte* Byte0 { get { return &_b0; } }
public UInt32 Value { get { return _b0 | ( _b1 << 8 ) | ( _b2 << 16 ); } }
}
UInt24 uint24 = new UInt24( 123 );
Are there any Int24 implementations in C#?
Upvotes: 2