--- name: vec status: documented runtime: pp source: src/runtime/pp/tie.rs --- ```{index} single: vec; Perl built-in (pp runtime) ``` # vec ## Synopsis ```perl my $val = vec($string, $offset, $bits); vec($string, $offset, $bits) = $value; ``` ## Description 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. ```perl 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 ``` ## See also pack, unpack