[M3devel] packing problem… how exactly does modula-3 pack data into records??

Dragiša Durić dragisha at m3w.org
Wed Jan 18 15:10:31 CET 2012

As per subject… I would like to pack this:

  TSPacketHeader = RECORD
    sync: BITS 8 FOR File.Byte;   (* Always 0x47 *)
    tErrInd,                      (* Transport Error Indicator *)
    pusi: BITS 1 FOR BOOLEAN;     (* Payload Unit Start Indicator *)
    transPrio: BITS 1 FOR [0..1];
    pid: BITS 13 FOR PID;
    transScramControl: BITS 2 FOR [0..3]; (* 00 means no scrambling *)
    afc: BITS 2 FOR [0..3]; (* 01 - no adaptation field, payload only *)
    cc: BITS 4 FOR Nibble;

My data, pusi is TRUE, sync is 0x47, pid is 4129 (0x1021), cc is 5 and afc is 0x1.Rest is zeros.

What I get is:

0000 1010 1000 0001 0101 0100

last five bits of pid; one bit for transPrio, one bit for pusi (TRUE), one bit for tErrInd;
first eight bits of pid
four bits of cc; two bits of abc; two bits for transScramControl

a mess. with pid being most special sort of it :).

Is this excected/normal? Wasn't whole idea os packing data into record about packing bits left-right-until-spent?


More information about the M3devel mailing list