using System; public class Test { static long Pack(long a24, long b16, long c24) { return a24<<40 | (b16&0xffffL)<<24 | (c24&0xffffff); } static void Unpack(long packed, out int a24, out int b16, out int c24) { a24 = (int)(packed >> 40); // Sign extension is done in the long b16 = ((int)(packed >> 8)) >> 16; // Sign extension is done in the int c24 = ((int)(packed << 8)) >> 8; // Sign extension is done in the int } public static void Main() { long p = Pack(0xFFABCD89, 0x7EDC, 0x123456); Console.WriteLine("{0:x}", p); int a, b, c; Unpack(p, out a, out b, out c); Console.WriteLine("{0:x} {1:x} {2:x}", a, b, c); } }