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);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJCgkKc3RhdGljIGxvbmcgUGFjayhsb25nIGEyNCwgbG9uZyBiMTYsIGxvbmcgYzI0KSB7CiAgICByZXR1cm4gYTI0PDw0MCB8IChiMTYmMHhmZmZmTCk8PDI0IHwgKGMyNCYweGZmZmZmZik7Cn0Kc3RhdGljIHZvaWQgVW5wYWNrKGxvbmcgcGFja2VkLCBvdXQgaW50IGEyNCwgb3V0IGludCBiMTYsIG91dCBpbnQgYzI0KSB7CiAgICBhMjQgPSAoaW50KShwYWNrZWQgPj4gNDApOyAvLyBTaWduIGV4dGVuc2lvbiBpcyBkb25lIGluIHRoZSBsb25nCiAgICBiMTYgPSAoKGludCkocGFja2VkID4+IDgpKSA+PiAxNjsgLy8gU2lnbiBleHRlbnNpb24gaXMgZG9uZSBpbiB0aGUgaW50CiAgICBjMjQgPSAoKGludCkocGFja2VkIDw8IDgpKSA+PiA4OyAgLy8gU2lnbiBleHRlbnNpb24gaXMgZG9uZSBpbiB0aGUgaW50Cn0KCQoJCglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJbG9uZyBwID0gUGFjaygweEZGQUJDRDg5LCAweDdFREMsIDB4MTIzNDU2KTsKCQlDb25zb2xlLldyaXRlTGluZSgiezA6eH0iLCBwKTsKCQlpbnQgYSwgYiwgYzsKCQlVbnBhY2socCwgb3V0IGEsIG91dCBiLCBvdXQgYyk7CgkJQ29uc29sZS5Xcml0ZUxpbmUoInswOnh9IHsxOnh9IHsyOnh9IiwgYSwgYiwgYyk7Cgl9Cn0=