Bit::Vector::Overload(3pm) | User Contributed Perl Documentation | Bit::Vector::Overload(3pm) |

Configuration $config = Bit::Vector->Configuration(); Bit::Vector->Configuration($config); $oldconfig = Bit::Vector->Configuration($newconfig); String Conversion $string = "$vector"; # depending on configuration print "\$vector = '$vector'\n"; Emptyness if ($vector) # if not empty (non-zero) if (! $vector) # if empty (zero) unless ($vector) # if empty (zero) Complement (one's complement) $vector2 = ~$vector1; $vector = ~$vector; Negation (two's complement) $vector2 = -$vector1; $vector = -$vector; Norm $norm = abs($vector); # depending on configuration Absolute $vector2 = abs($vector1); # depending on configuration Concatenation $vector3 = $vector1 . $vector2; $vector1 .= $vector2; $vector1 = $vector2 . $vector1; $vector2 = $vector1 . $scalar; # depending on configuration $vector2 = $scalar . $vector1; $vector .= $scalar; Duplication $vector2 = $vector1 x $factor; $vector x= $factor; Shift Left $vector2 = $vector1 << $bits; $vector <<= $bits; Shift Right $vector2 = $vector1 >> $bits; $vector >>= $bits; Union $vector3 = $vector1 | $vector2; $vector1 |= $vector2; $vector2 = $vector1 | $scalar; $vector |= $scalar; $vector3 = $vector1 + $vector2; # depending on configuration $vector1 += $vector2; $vector2 = $vector1 + $scalar; $vector += $scalar; Intersection $vector3 = $vector1 & $vector2; $vector1 &= $vector2; $vector2 = $vector1 & $scalar; $vector &= $scalar; $vector3 = $vector1 * $vector2; # depending on configuration $vector1 *= $vector2; $vector2 = $vector1 * $scalar; $vector *= $scalar; ExclusiveOr $vector3 = $vector1 ^ $vector2; $vector1 ^= $vector2; $vector2 = $vector1 ^ $scalar; $vector ^= $scalar; Set Difference $vector3 = $vector1 - $vector2; # depending on configuration $vector1 -= $vector2; $vector1 = $vector2 - $vector1; $vector2 = $vector1 - $scalar; $vector2 = $scalar - $vector1; $vector -= $scalar; Addition $vector3 = $vector1 + $vector2; # depending on configuration $vector1 += $vector2; $vector2 = $vector1 + $scalar; $vector += $scalar; Subtraction $vector3 = $vector1 - $vector2; # depending on configuration $vector1 -= $vector2; $vector1 = $vector2 - $vector1; $vector2 = $vector1 - $scalar; $vector2 = $scalar - $vector1; $vector -= $scalar; Multiplication $vector3 = $vector1 * $vector2; # depending on configuration $vector1 *= $vector2; $vector2 = $vector1 * $scalar; $vector *= $scalar; Division $vector3 = $vector1 / $vector2; $vector1 /= $vector2; $vector1 = $vector2 / $vector1; $vector2 = $vector1 / $scalar; $vector2 = $scalar / $vector1; $vector /= $scalar; Modulo $vector3 = $vector1 % $vector2; $vector1 %= $vector2; $vector1 = $vector2 % $vector1; $vector2 = $vector1 % $scalar; $vector2 = $scalar % $vector1; $vector %= $scalar; Exponentiation $vector3 = $vector1 ** $vector2; $vector1 **= $vector2; $vector2 = $vector1 ** $scalar; $vector2 = $scalar ** $vector1; $vector **= $scalar; Increment ++$vector; $vector++; Decrement --$vector; $vector--; Lexical Comparison (unsigned) $cmp = $vector1 cmp $vector2; if ($vector1 lt $vector2) if ($vector1 le $vector2) if ($vector1 gt $vector2) if ($vector1 ge $vector2) $cmp = $vector cmp $scalar; if ($vector lt $scalar) if ($vector le $scalar) if ($vector gt $scalar) if ($vector ge $scalar) Comparison (signed) $cmp = $vector1 <=> $vector2; if ($vector1 < $vector2) # depending on configuration if ($vector1 <= $vector2) if ($vector1 > $vector2) if ($vector1 >= $vector2) $cmp = $vector <=> $scalar; if ($vector < $scalar) # depending on configuration if ($vector <= $scalar) if ($vector > $scalar) if ($vector >= $scalar) Equality if ($vector1 eq $vector2) if ($vector1 ne $vector2) if ($vector eq $scalar) if ($vector ne $scalar) if ($vector1 == $vector2) if ($vector1 != $vector2) if ($vector == $scalar) if ($vector != $scalar) Subset Relationship if ($vector1 <= $vector2) # depending on configuration True Subset Relationship if ($vector1 < $vector2) # depending on configuration Superset Relationship if ($vector1 >= $vector2) # depending on configuration True Superset Relationship if ($vector1 > $vector2) # depending on configuration

- •
- Boolean values

- •
- Negative numbers
**UNSIGNED**.

- •
- Overloaded operators configuration

- •
- "Big integers"
**ALL**your "big integer" constants in your programs in (double or single) quotes.$vector /= 10; # ok because number is small $vector /= -10; # ok for same reason $vector /= "10"; # always correct $vector += "1152921504606846976"; # quotes probably required here

Bit::Vector->Configuration("input=decimal");

- •
- Valid operands for overloaded operators
"$vector" if ($vector) if (!$vector) ~$vector -$vector abs($vector) ++$vector $vector++ --$vector $vector--

.= x= <<= >>= |= &= ^= += -= *= /= %= **=

**ALWAYS**a bit vector and the right operand is**ALWAYS**a number (which is the factor indicating how many times the operator is to be applied).. | & ^ + - * / % ** <=> cmp == eq != ne < lt <= le > gt >= ge

.= |= &= ^= += -= *= /= %= **=

input = bit indices (default) : numeric input = hexadecimal : string input = binary : string input = decimal : string (in general) input = decimal : numeric (if small enough) input = enumeration : string

- •
- Bit order
**RIGHTMOST**bit is always the**LEAST SIGNIFICANT**one, and the**LEFTMOST**bit is always the**MOST SIGNIFICANT**bit.

- •
- Matching sizes

- •
- Index ranges

- •
- "$config = Bit::Vector->Configuration();"

- •
- "Bit::Vector->Configuration($config);"

- •
- "$oldconfig =
Bit::Vector->Configuration($newconfig);"
**BEFORE**any modifications are applied) and which can be fed back to this method later in order to restore the previous configuration.+ the way scalar operands (replacing one of the two bit vector object operands) are automatically converted internally into a bit vector object of their own, + the operation certain overloaded operators perform, i.e., an operation with sets or an arithmetic operation, + the format to which bit vectors are converted automatically when they are enclosed in double quotes.

+ "^scalar", "^input", "^in$" + "^operator", "^semantic", "^ops$" + "^string", "^output", "^out$"

+ "<which>" = "^scalar", "^input", "^in$": "<value>" = * "^bit$", "^index", "^indice" * "^hex" * "^bin" * "^dec" * "^enum" + "<which>" = "^operator", "^semantic", "^ops$": "<value>" = * "^set$" * "^arithmetic" + "<which>" = "^string", "^output", "^out$": "<value>" = * "^hex" * "^bin" * "^dec" * "^enum"

"Any scalar input I provide should be considered to be = a bit index" "I want to have operator semantics suitable for = arithmetics" "Any bit vector in double quotes is to be output as = an enumeration"

**SCALAR INPUT:****OPERATOR SEMANTICS:**+ set union ( set1 u set2 ) - set difference ( set1 \ set2 ) * set intersection ( set1 n set2 ) < true subset relationship ( set1 < set2 ) <= subset relationship ( set1 <= set2 ) > true superset relationship ( set1 > set2 ) >= superset relationship ( set1 >= set2 )

+ addition ( num1 + num2 ) - subtraction ( num1 - num2 ) * multiplication ( num1 * num2 ) < "less than" comparison ( num1 < num2 ) <= "less than or equal" comparison ( num1 <= num2 ) > "greater than" comparison ( num1 > num2 ) >= "greater than or equal" comparison ( num1 >= num2 )

**SIGNED**.**UNSIGNED**operands, use the operators ""lt"", ""le"", ""gt"" and ""ge"" instead (in contrast to the operators above, these operators are**NOT**affected by the "operator semantics" setting).**STRING OUTPUT:**print "\$vector = '$vector'\n"; $string = "$vector";

**BEWARE**that the conversion to decimal numbers is inherently slow; it can easily take up several seconds for a single large bit vector!**EXAMPLES:**Scalar Input = Bit Index Operator Semantics = Set Operators String Output = Hexadecimal

Bit::Vector->Configuration("in=bin,ops=arithmetic,out=bin"); print Bit::Vector->Configuration(), "\n";

Scalar Input = Binary Operator Semantics = Arithmetic Operators String Output = Binary

Bit::Vector->Configuration("operators = arithmetic");

- •
- "$vector"

- •
- "if ($vector)"
**ALL**bits of the corresponding bit vector are cleared.

- •
- "if (!$vector)"
**ALL**bits of the corresponding bit vector are cleared, and it is false if the corresponding bit vector contains at least one set bit.**NOT**the same as using the method ""is_full()"", which returns true if**ALL**bits of the corresponding bit vector are**SET**.

- •
- "~$vector"

- •
- "-$vector" (unary minus)

- •
- "abs($vector)"

- •
- "$vector1 . $vector2"

- •
- "$vector x $factor"

- •
- "$vector << $bits"

- •
- "$vector >> $bits"

- •
- "$vector1 | $vector2"

- •
- "$vector1 & $vector2"

- •
- "$vector1 ^ $vector2"

- •
- "$vector1 + $vector2"

- •
- "$vector1 - $vector2"

- •
- "$vector1 * $vector2"

- •
- "$vector1 / $vector2"

- •
- "$vector1 % $vector2"

- •
- "$vector1 ** $vector2"

- •
- "$vector1 .= $vector2;"

- •
- "$vector x= $factor;"

- •
- "$vector <<= $bits;"

- •
- "$vector >>= $bits;"

- •
- "$vector1 |= $vector2;"

- •
- "$vector1 &= $vector2;"

- •
- "$vector1 ^= $vector2;"

- •
- "$vector1 += $vector2;"

- •
- "$vector1 -= $vector2;"

- •
- "$vector1 *= $vector2;"

- •
- "$vector1 /= $vector2;"

- •
- "$vector1 %= $vector2;"

- •
- "$vector1 **= $vector2;"

- •
- "++$vector", "$vector++"

- •
- "--$vector", "$vector--"

- •
- "($vector1 cmp $vector2)"
**UNSIGNED**bit vectors.

- •
- "($vector1 eq $vector2)"

- •
- "($vector1 ne $vector2)"

- •
- "($vector1 lt $vector2)"
**UNSIGNED**bit vectors.

- •
- "($vector1 le $vector2)"
**UNSIGNED**bit vectors.

- •
- "($vector1 gt $vector2)"
**UNSIGNED**bit vectors.

- •
- "($vector1 ge $vector2)"
**UNSIGNED**bit vectors.

- •
- "($vector1 <=> $vector2)"
**SIGNED**bit vectors.

- •
- "($vector1 == $vector2)"

- •
- "($vector1 != $vector2)"

- •
- "($vector1 < $vector2)"
**SIGNED**bit vectors.

- •
- "($vector1 <= $vector2)"
**SIGNED**bit vectors.

- •
- "($vector1 > $vector2)"
**SIGNED**bit vectors.

- •
- "($vector1 >= $vector2)"
**SIGNED**bit vectors.

Steffen Beyer mailto:STBEY@cpan.org http://www.engelschall.com/u/sb/download/

2017-07-22 | perl v5.26.0 |