- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl vec Function
Description
This function uses the string specified EXPR as a vector of unsigned integers. The NUMBITS parameter is the number of bits that are reserved for each entry in the bit vector.
This must be a power of two from 1 to 32. Note that the offset is the marker for the end of the vector, and it counts back the number of bits specified to find the start. Vectors can be manipulated with the logical bitwise operators |, & and ^.
Syntax
Following is the simple syntax for this function −
vec EXPR, OFFSET, BITS
Return Value
This function returns the value of the bit field specified by OFFSET.
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl -w $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");
When above code is executed, it produces the following result −
vec() Has a created a string of nybbles, in hex: 0001000a0003000f
perl_function_references.htm
Advertisements