Unpack ( template, expression )
The TEMPLATE is a sequence of characters that give the order and type of values, as follows:
You may prefix a field with a %<number> to indicate that you want a <number>-bit checksum of the items instead of the items themselves. Default is a 16-bit checksum. Checksum is calculated by summing numeric values of expanded values (for string fields the sum of ord($char) is taken, for bit fields the sum of zeroes and ones). The following efficiently counts the number of set bits in a bit vector: $setbits = unpack("%32b*", $selectmask);