Front page | perl.perl5.porters |
Postings from October 1999
[PATCH 5.005_62] Another round of pack/vec docs patches
Thread Next
From:
Ilya Zakharevich
Date:
October 27, 1999 15:57
Subject:
[PATCH 5.005_62] Another round of pack/vec docs patches
Message ID:
199910272257.SAA29928@monk.mps.ohio-state.edu
--- ./pod/perlfunc.pod~ Wed Oct 13 12:13:36 1999
+++ ./pod/perlfunc.pod Wed Oct 27 18:52:56 1999
@@ -2838,16 +2838,22 @@ all circumstances.
=item *
Likewise, the C<"b"> and C<"B"> fields pack a string that many bits long.
-Each byte of the input field generates 1 bit of the result basing on
+Each byte of the input field of pack() generates 1 bit of the result basing on
the least-signifant bit of each input byte, i.e., on C<ord($byte)%2>.
-In particular, bytes C<"0"> and C<"1"> generate bits 0 and 1.
+In particular, bytes C<"0"> and C<"1"> generate bits 0 and 1,
+similarly for bytes C<"\0"> and C<"\1">.
-Starting from the beginning of the input string, each 8-tuple of bytes
-is converted to 1 byte of output. If the length of the input string
-is not divisible by 8, the remainder is packed as if padded by 0s.
-Similarly, during unpack()ing the "extra" bits are ignored.
+Starting from the beginning of the input string of pack(), each
+8-tuple of bytes is converted to 1 byte of output. With format C<"b">
+the first byte of the 8-tuple goes to the least-significant bit of a
+byte, with format C<"B"> it goes to the most-significant bit of a
+byte.
+
+If the length of the input string is not divisible by 8, the remainder
+is packed as if padded by 0s. Similarly, during unpack()ing the
+"extra" bits are ignored.
-If the input string is longer than needed, extra bytes are ignored.
+If the input string of pack() is longer than needed, extra bytes are ignored.
A C<*> for the repeat count of pack() means to use all the bytes of
the input field. On unpack()ing the bits are converted to a string
of C<"0">s and C<"1">s.
@@ -2857,6 +2863,30 @@ of C<"0">s and C<"1">s.
The C<"h"> and C<"H"> fields pack a string that many nybbles (4-bit groups,
representable as hexadecimal digits, 0-9a-f) long.
+Each byte of the input field of pack() generates 4 bits of the result.
+For non-alphabetical bytes the result is based on 4 least-signifant
+bits of the input byte, i.e., on C<ord($byte)%16>. In particular,
+bytes C<"0"> and C<"1"> generate nybbles 0 and 1, similarly for bytes
+C<"\0"> and C<"\1">. For alphabetical bytes the result is compatible
+with the usual notation, so C<"a"> and C<"A"> generate nybble
+C<0xa==10> (but this is extended to C<"a".."z"> and C<"A".."Z"> with
+results wrapping after 15, which is C<"f">/C<"F">). In other words,
+C<"g">/C<"G"> convert to 0, C<"h">/C<"H"> to 1, and C<"z">/C<"Z"> to 3.
+
+Starting from the beginning of the input string of pack(), each pair
+of bytes is converted to 1 byte of output. With format C<"h"> the
+first byte of the pair goes to least-significant nybble of a byte,
+with format C<"H"> it goes to the most-significant nybble.
+
+If the length of the input string is not even, it behaves as if padded
+by byte 0. Similarly, during unpack()ing the "extra" nybbles are
+ignored.
+
+If the input string of pack() is longer than needed, extra bytes are ignored.
+A C<*> for the repeat count of pack() means to use all the bytes of
+the input field. On unpack()ing the bits are converted to a string
+of hexadecimal digits.
+
=item *
The C<"p"> type packs a pointer to a null-terminated string. You are
@@ -5094,6 +5124,20 @@ as an unsigned integer. BITS therefore
that are reserved for each element in the bit vector. This must
be a power of two from 1 to 32 (or 64, if your platform supports
that).
+
+If BITS is 8, "elements" coincide with bytes of the string.
+
+If BITS is 16 or more, bytes of the string are grouped into chunks of
+size BITS/8, and each group is converted to a number as with
+pack()/unpack() with big-endian formats C<n>/C<N> (and analoguously
+for BITS==64). See L<"pack"> for details.
+
+If bits is 4 or less, the string is broken into bytes, then the bits
+of each byte are broken into 8/BITS groups. Bits of a byte are
+numbered in a little-endianI<ish> way, as in C<0x01>, C<0x02>,
+C<0x04>, C<0x08>, C<0x10>, C<0x20>, C<0x40>, C<0x80>. Say, breaking a
+byte C<chr(0x36)> into two groups gives a list C<(0x6, 0x3)>, into 4
+groups gives C<(0x2, 0x1, 0x3, 0x0)>.
C<vec> may also be assigned to, in which case parentheses are needed
to give the expression the correct precedence as in
Thread Next
-
[PATCH 5.005_62] Another round of pack/vec docs patches
by Ilya Zakharevich