SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG

BotDetect - Real-Time Bot Detection API
 
 

MAN page from Old RedHat 6.X perl-Math-BaseCalc-1.007-6.i386.rpm

BaseCalc

Section: User Contributed Perl Documentation (3)
Updated: perl 5.005, patch 03
Index 

NAME

Math::BaseCalc - Convert numbers between various bases 

SYNOPSIS

  use Math::BaseCalc;
  my $calc = new Math::BaseCalc(digits => [0,1]); #Binary  my $bin_string = $calc->to_base(65); # Convert 465 to binary
  $calc->digits('oct'); # Octal  my $number = $calc->from_base('1574'); # Convert octal 1574 to decimal
 

DESCRIPTION

This module facilitates the conversion of numbers between variousnumber bases. You may define your own digit sets, or use any ofseveral predefined digit sets.

The to_base() and from_base() methods convert between Perl numbers andstrings which represent these numbers in other bases. For instance,if you're using the binary digit set [0,1], $calc->to_base(5) willreturn the string ``101''. $calc->from_base("101") will return thenumber 5.

To convert between, say, base 7 and base 36, use the 2-step processof first converting to a Perl number, then to the desired base for theresult:

 $calc7  = new Math::BaseCalc(digits=>[0..7]); $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z'];  $in_base_36 = $calc36->to_base( $calc7->from_base('3506') );
If you just need to handle regular octal & hexdecimal strings, youprobably don't need this module. See the sprintf(), oct(), and hex()Perl functions. 

METHODS


* new Math::BaseCalc

* new Math::BaseCalc(digits=>...)
Create a new base calculator. You may specify the digit set to use,by either giving the digits in a list reference (in increasing order,with the `zero' character first in the list) or by specifying the nameof one of the predefined digit sets (see the digit() method below).
* $calc->to_base(NUMBER)
Converts a number to a string representing that number in theassociated base. Currently only handles integers.
* $calc->from_base(STRING)
Converts a string representing a number in the associated base to aPerl integer. Currently only handles integers. The behavior when fedstrings with characters not in $calc's digit set is currentlyundefined.
* $calc->digits

* $calc->digits(...)
Get/set the current digit set of the calculator. With no arguments,simply returns a list of the characters that make up the current digitset. To change the current digit set, pass a list referencecontaining the new digits, or the name of a predefined digit set.Currently the predefined digit sets are:

       bin => [0,1],       hex => [0..9,'a'..'f'],       HEX => [0..9,'A'..'F'],       oct => [0..7],       64  => ['A'..'Z','a'..'z',0..9,'+','/'],       62  => [0..9,'a'..'z','A'..'Z'],  Examples:  $calc->digits('bin');  $calc->digits([0..7]);  $calc->digits([qw(w a l d o)]);
If any of your ``digits'' has more than one character, the behavior iscurrently undefined.
 

QUESTIONS

The `64' digit set is meant to be useful for Base64 encoding. I tookit from the MIME::Base64.pm module. Does it look right? It's sure ina strange order. 

AUTHOR

Ken Williams, kenAATTforum.swarthmore.edu 

COPYRIGHT

This is free software in the colloquial nice-guy sense of the word.Copyright (c) 1999, Ken Williams. You may redistribute and/or modifyit under the same terms as Perl itself. 

SEE ALSO

perl(1).


 

Index

NAME
SYNOPSIS
DESCRIPTION
METHODS
QUESTIONS
AUTHOR
COPYRIGHT
SEE ALSO

This document was created byman2html,using the manual pages.
 
ICM Bot detect detector