vec
Treats a string as a bit vector and accesses individual bitfields.
Treats EXPR as a bit vector made up of elements of width BITS and returns the unsigned integer value of the element at OFFSET. BITS must be a power of 2 from 1 to 32.
As an lvalue, vec stores values into the specified bitfield,
growing the string as needed.
my $flags = "";
vec($flags, 0, 8) = 255; # Set byte 0 to 255
vec($flags, 1, 8) = 10; # Set byte 1 to 10
my $val = vec($flags, 0, 8); # Get byte 0 (255)
my $bit = vec($flags, 5, 1); # Get bit 5 of byte 0
Synopsis
my $val = vec($string, $offset, $bits);
vec($string, $offset, $bits) = $value;