You could use System.BitConverter, as cyreon suggested, and process 24 bits at a time, eg:
Code:
using System;
class Test
{
static void Main( )
{
byte [ ]
data = new byte[ ]
{
0x12,
0x34,
0x56,
0x12,
0x34,
0x56,
0x12,
0x34,
0x56,
0x12,
0x34,
0x56,
/*
Padding, to prevent access violation
*/
0x00
};
/*
Special calculation needed due to padding
*/
int
limit = data.Length - ( data.Length % 3 );
for( int index = 0; index < limit; index += 3 )
{
int
buffer24 = BitConverter.ToInt32( data, index ) & 0x00ffffff,
first12 = buffer24 & 0xfff,
second12 = ( buffer24 >> 12 );
Console.Write( "first12 : 0x" + Convert.ToString( first12, 16 ).PadLeft( 3, '0' ) + "\n" );
Console.Write( "second12: 0x" + Convert.ToString( second12, 16 ).PadLeft( 3, '0' ) + "\n" );
/*
Put first12 and second12 into an array or such
*/
}
}
}