vec EXPR, OFFSET, BITS |
使用指定的字符串EXPR作为载体的无符号整数。NUMBITS参数是保留位向量中的每个条目的位的数目。这必须是从1到32的幂。请注意,该偏移量是为结束的矢量的标记,它计数回到指定找到开始的比特的数目。向量可以被操纵的逻辑位运算符|,&和^。
该位字段的值指定的偏移OFFSET。
#!/usr/bin/perl -w #by www.gitbook.net $vec = ''; vec($vec, 3, 4) = 1; # bits 0 to 3 vec($vec, 7, 4) = 10; # bits 4 to 7 vec($vec, 11, 4) = 3; # bits 8 to 11 vec($vec, 15, 4) = 15; # bits 12 to 15 # As there are 4 bits per number this can # be decoded by unpack() as a hex number print("vec() Has a created a string of nybbles, in hex: ", unpack("h*", $vec), "\n");
这将产生以下结果:
vec() Has a created a string of nybbles,
in hex: 0001000a0003000f