----boundary-LibPST-iamunique-1195912186_-_-
Content-type: text/plain
> I have advanced a little bit concerning bit manipulation and
>unsigned assignments. As a practical example, today I accomplished
>a mundane task of packing two bytes from a byte buffer into
>a 32-bit integer. Something, which in C is perhaps as simple as
>
> intVar = bhi<<8 + blo;
>
>The following code fragment is a bit more complex because the sign
>bits get in the way and have to be cut. I wonder if such manipulations
>are the most efficient way of packing/unpacking data. In any case,
>I did not have to use SYSTEM to accomplish this.
>
> VAR setHi,setLo: SET; (*bit field variables (hi,lo byte)*)
>
> FOR i := 0 TO len-1 DO
> (*Pack two consequtive bytes into an integer. MSB is first.*)
> (*Cutting with bit masks avoids sign extension*)
> setHi := BITS(ASH(buffer[2*i],8)) * {8..15};
> setLo := BITS( buffer[2*i+1]) * {0..7};
> histogram.bin [i] := ORD(setHi + setLo);
> END;
Maybe the following (untested) arithmetical approach
seems more familiar:
PROCEDURE BytePack (b0, b1 : BYTE) : INTEGER;
VAR
a, b : INTEGER;
BEGIN
a := b0 MOD 256;
b := b1 MOD 256;
RETURN ASH (b, 8) + a
END BytePack;
Would the 'inlined' version
ROCEDURE BytePack (b0, b1 : BYTE) : INTEGER;
BEGIN
RETURN ASH (b1 MOD 256, 8) + (b0 MOD 256)
END BytePack;
use INTEGERS internally, and work the same?
Robert Campbell
--------------------------------------------
To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
blackbox-request{([at]})nowhere.xy
To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.
Send any problem reports or questions related to this email list to the list owner at
owner-blackbox{([at]})nowhere.xy
Current posting policy:
a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.
b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.
----boundary-LibPST-iamunique-1195912186_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYx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