tw29669a.pp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. {$mode objfpc}
  2. program Project1;
  3. uses
  4. SysUtils;
  5. type
  6. TPackedIdLevel1 = 0..255;
  7. TPackedIdLevel2 = 0..65535;
  8. TPackedIdLevel3 = 0..65535;
  9. TPackedIdLevel4 = 0..65535;
  10. TPackedIdLevel5 = 0..255;
  11. TPackedId = bitpacked record
  12. clusterId : TPackedIdLevel5;
  13. esmId : TPackedIdLevel1;
  14. agentId : TPackedIdLevel4;
  15. dataSourceId : TPackedIdLevel3;
  16. deviceId : TPackedIdLevel2;
  17. end;
  18. function PackedIdToStr(const ipsid : qword) : string;
  19. begin
  20. result := IntToStr(TPackedId(ipsid).esmId) + '-' +
  21. IntToStr(TPackedId(ipsid).deviceId) + '-' +
  22. IntToStr(TPackedId(ipsid).dataSourceId) + '-' +
  23. IntToStr(TPackedId(ipsid).agentId) + '-' +
  24. IntToStr(TPackedId(ipsid).clusterId);
  25. if TPackedId(ipsid).clusterid<>123 then
  26. halt(1);
  27. if TPackedId(ipsid).agentid<>45678 then
  28. halt(2);
  29. if TPackedId(ipsid).datasourceid<>9012 then
  30. halt(3);
  31. if TPackedId(ipsid).deviceid<>34567 then
  32. halt(4);
  33. if TPackedId(ipsid).esmid<>89 then
  34. halt(5);
  35. end;
  36. var
  37. pi: TPackedId;
  38. begin
  39. pi.clusterid:=123;
  40. pi.agentid:=45678;
  41. pi.datasourceid:=9012;
  42. pi.deviceid:=34567;
  43. pi.esmid:=89;
  44. writeln(PackedIdToStr(qword(pi)));
  45. end.