| Bit-Vector documentation | view source | Contained in the Bit-Vector distribution. |
Bit::Vector::String - Generic string import/export for Bit::Vector
use Bit::Vector::String;
to_Oct
$string = $vector->to_Oct();
from_Oct
$vector->from_Oct($string);
new_Oct
$vector = Bit::Vector->new_Oct($bits,$string);
String_Export
$string = $vector->String_Export($type);
String_Import
$type = $vector->String_Import($string);
new_String
$vector = Bit::Vector->new_String($bits,$string);
($vector,$type) = Bit::Vector->new_String($bits,$string);
$string = $vector->to_Oct();
join('', ...)".
to_Bin()" (which is realized in C):
Benchmark: timing 10000 iterations of to_Bin, to_Hex, to_Oct...
to_Bin: 1 wallclock secs ( 1.09 usr + 0.00 sys = 1.09 CPU)
to_Hex: 1 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU)
to_Oct: 40 wallclock secs (40.16 usr + 0.05 sys = 40.21 CPU)
$string = '0o' . $vector->to_Oct();
$vector->from_Oct($string);
to_Oct()" (see above).
split(//, $string)".
Chunk_List_Store()",
which expects the least significant chunks of data at the beginning
of a list.
from_Bin()" (which is realized in C):
Benchmark: timing 10000 iterations of from_Bin, from_Hex, from_Oct... from_Bin: 1 wallclock secs ( 1.13 usr + 0.00 sys = 1.13 CPU) from_Hex: 1 wallclock secs ( 0.80 usr + 0.00 sys = 0.80 CPU) from_Oct: 46 wallclock secs (44.95 usr + 0.00 sys = 44.95 CPU)
$vector = Bit::Vector->new_Oct($bits,$string);
$bits" bits) and to initialize it
all in one go.
new()" and then stores the given string in the newly created
bit vector using the same approach as the method "from_Oct()"
(described above).
split(//, $string)".
new()" in Bit::Vector(3) for
possible causes) or if the given string cannot be converted successfully
(see the description of the method "from_Oct()" above for details).
$bits" given has the value "undef",
the method will automatically allocate a bit vector with a size
(i.e., number of bits) of three times the length of the given string
(since every octal digit is worth three bits).
new_Hex()", "new_Bin()", "new_Dec()" and "new_Enum()"
(which are realized in C, internally); these methods will silently
assume a value of 0 bits if "undef" is given (and may warn
about the "Use of uninitialized value" if warnings are enabled). $string = $vector->String_Export($type);
$type":
1 | b | bin => binary (using "to_Bin()") 2 | o | oct => octal (using "to_Oct()") 3 | d | dec => decimal (using "to_Dec()") 4 | h | hex | x => hexadecimal (using "to_Hex()") 5 | e | enum => enumeration (using "to_Enum()") 6 | p | pack => packed binary (using "Block_Read()")
$type" is ignored.
$type" is omitted or "undef" or false ("0"
or the empty string), a hexadecimal string is returned
as the default format.
$type" does not have any of the values described
above, a fatal "unknown string type" will occur.
String_Import()" and "new_String()" (described
below), the method "String_Export()" provides
uniquely identifying prefixes (and, in one case,
a suffix) as follows:
1 | b | bin => '0b' . $vector->to_Bin();
2 | o | oct => '0o' . $vector->to_Oct();
3 | d | dec => $vector->to_Dec(); # prefix is [+-]
4 | h | hex | x => '0x' . $vector->to_Hex();
5 | e | enum => '{' . $vector->to_Enum() . '}';
6 | p | pack => ':' . $vector->Size() .
':' . $vector->Block_Read();
to_Enum()") only contains one element, this element could
be mistaken for a representation of the entire bit vector
(instead of just one bit) in decimal.
$type = $vector->String_Import($string);
String_Export()",
"to_Bin()", "to_Oct()", "to_Dec()", "to_Hex()",
"to_Enum()", "Block_Read()" or manually or by another
program.
String_Export()"
(see immediately above).
to_Bin()", "to_Oct()", "to_Dec()", "to_Hex()"
and "to_Enum()".
String_Export()",
due to the fact that a string may be a valid representation in
more than one format, this may lead to unwanted results.
Block_Store()".
String_Export()" or to provide
some uniquely identifying prefix (and suffix, in one case)
yourself:
binary => '0b' . $string;
octal => '0o' . $string;
decimal => '+' . $string; # in case "$string"
=> '-' . $string; # has no sign yet
hexadecimal => '0x' . $string;
=> '0h' . $string;
enumeration => '{' . $string . '}';
=> '[' . $string . ']';
=> '<' . $string . '>';
=> '(' . $string . ')';
packed binary => ':' . $vector->Size() .
':' . $vector->Block_Read();
from_Bin()",
"from_Oct()", "from_Dec()", "from_Hex()",
"from_Enum()" and "Block_Store()" for actually
importing the contents of the string into the given
bit vector. See their descriptions here in this document
and in Bit::Vector(3) for any further conditions that
must be met and corresponding possible fatal error messages.
1 => binary
2 => octal
3 => decimal
4 => hexadecimal
5 => enumeration
6 => packed binary
$vector = Bit::Vector->new_String($bits,$string);
($vector,$type) = Bit::Vector->new_String($bits,$string);
$bits" bits) and to initialize it
all in one go.
new()" and then stores the given string in the newly created
bit vector using the same approach as the method "String_Import()"
(described immediately above).
new()" in Bit::Vector(3) for
possible causes) or if the given string cannot be converted successfully
(see the description of the method "String_Import()" above for details).
$bits" given has the value "undef", the
method will automatically determine this value for you and allocate
a bit vector of the calculated size.
new_Hex()", "new_Bin()", "new_Dec()" and "new_Enum()"
(which are realized in C, internally); these methods will silently
assume a value of 0 bits if "undef" is given (and may warn
about the "Use of uninitialized value" if warnings are enabled).
binary => length($string); octal => 3 * length($string); decimal => int( length($string) * log(10) / log(2) + 1 ); hexadecimal => 4 * length($string); enumeration => maximum of values found in $string + 1 packed binary => $string =~ /^:(\d+):/;
String_Import()".Bit::Vector(3), Bit::Vector::Overload(3).
This man page documents "Bit::Vector::String" version 7.1.
Steffen Beyer mailto:STBEY@cpan.org http://www.engelschall.com/u/sb/download/
Copyright (c) 2004 - 2009 by Steffen Beyer. All rights reserved.
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".
The C library at the core of this Perl module can additionally be redistributed and/or modified under the terms of the "GNU Library General Public License".
Please refer to the files "Artistic.txt", "GNU_GPL.txt" and "GNU_LGPL.txt" in this distribution for details!
This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "GNU General Public License" for more details.
| Bit-Vector documentation | view source | Contained in the Bit-Vector distribution. |