optimized for speed on some operations, and for at least some
programmers the notation might be familiar.
-=item B<How do I convert hexadecimal into decimal:>
+=over 4
+
+=item How do I convert hexadecimal into decimal
Using perl's built in conversion of 0x notation:
$vec = Bit::Vector->new_Hex(32, "DEADBEEF");
$dec = $vec->to_Dec();
-=item B<How do I convert from decimal to hexadecimal:>
+=item How do I convert from decimal to hexadecimal
Using sprint:
$vec->Resize(32); # suppress leading 0 if unwanted
$hex = $vec->to_Hex();
-=item B<How do I convert from octal to decimal:>
+=item How do I convert from octal to decimal
Using Perl's built in conversion of numbers with leading zeros:
$vec->Chunk_List_Store(3, split(//, reverse "33653337357"));
$dec = $vec->to_Dec();
-=item B<How do I convert from decimal to octal:>
+=item How do I convert from decimal to octal
Using sprintf:
$vec = Bit::Vector->new_Dec(32, -559038737);
$oct = reverse join('', $vec->Chunk_List_Read(3));
-=item B<How do I convert from binary to decimal:>
+=item How do I convert from binary to decimal
Perl 5.6 lets you write binary numbers directly with
the 0b notation:
$vec = Bit::Vector->new_Bin(32, "11011110101011011011111011101111");
$dec = $vec->to_Dec();
-=item B<How do I convert from decimal to binary:>
+=item How do I convert from decimal to binary
Using unpack;
The remaining transformations (e.g. hex -> oct, bin -> hex, etc.)
are left as an exercise to the inclined reader.
+=back
=head2 Why doesn't & work the way I want it to?
for $orbit ( values %orbits ) {
($orbit **= 3) *= (4/3) * 3.14159;
}
-
+
Prior to perl 5.6 C<values> returned copies of the values,
so older perl code often contains constructions such as
C<@orbits{keys %orbits}> instead of C<values %orbits> where
the hash is to be modified.
-
+
=head2 How do I select a random element from an array?
Use the rand() function (see L<perlfunc/rand>):