3

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
user1926930
  • 77
  • 1
  • 7
  • See: http://stackoverflow.com/questions/17110567/converting-byte-array-to-int24/18195017#18195017 – Habib Aug 12 '13 at 19:22

1 Answers1

2

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#?

Community
  • 1
  • 1
Darren
  • 68,902
  • 24
  • 138
  • 144