Skip to content

Latest commit

 

History

History
245 lines (158 loc) · 6.71 KB

File metadata and controls

245 lines (158 loc) · 6.71 KB

NAME

Math::BaseCalc - 罕������ɱ�堺�育����ф�医�ゃ��紊������������≪�吾�ャ�若�

VERSION

version 1.017

SYNOPSIS

use Math::BaseCalc;

my $calc = new Math::BaseCalc(digits => [0,1]); # 2 ��我�
my $bin_string = $calc->to_base(465); # 465 ��� 2 ��我�違��紊��

$calc->digits('oct'); # 8 ��我�
my $number = $calc->from_base('1574'); # 8 ��我�違�� 1574 ��� 10 ��我�違��紊��

DESCRIPTION

�����勉�≪�吾�ャ�若�˨�壔��罕������ɱ�堺�育����勖�医�ゅ��������絎号����˨����������勉�с����� ������������������������������罕������ɱ�堺�違�勖��絖���祉��������篏帥�������������с����障�������� 篁紙����勐�堺�違�勖��絖���祉��������絎�臂í����������������с����障�����

荐恰絵鐚� ���digit set������������絖���祉����������◑┳�����⓾����障��������digit set��� �����壔�����絽悟�������������� 16 ��我�違�ц�������違��0-9a-f�����勉�������с����� 綏с��茵◐憗����d�������˩戎��������⓾�����茵◐憗����������井����������⓾��������������

to_base() ��<�純�������� from_base() ��<�純�������壔��Perl ��с�勖�医�ゃ� 篁���勐�堺�違�勖�医�ゃ��茵�������絖������勰����у����������障�����箴������違��2 ��我�違��茵���� ���絖���祉�������������� [0,1] ��������������ŝ����違��$calc->to_base(5)��壩��絖���� "101" ��� 菴������障�����$calc->from_base("101") ��壩�医�ゃ��菴������障�����

荐恰絵鐚�紊���ʃ┳��������掩�������隙��箴������帥�☎��茹c����⓾��������������:-)

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

7 ��我�違�� 36 ��我�違�勰����у�������������������˨�壔����������� Perl ��勖�医�ゃ��紊���������� �����勖❶��������勛��������絽������������堺�違��紊������������������� 2 罧級����勉����㏍�祉�鴻�� 腟����綽�荀������������障�����:

$calc7  = new Math::BaseCalc(digits=>[0..6]);
$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, you probably don't need this module. See the sprintf(), oct(), and hex() Perl functions.

���������罔�羣������� 8 ��我�違�� 16 ��我�違�勖��絖���������宴��綽�荀������������ŝ����違�� �����勉�≪�吾�ャ�若�˨�����������綽�荀���壔�������障�������� sprintf() ��� oct()��� hex() ��ŝ�í�� Perl ��勰�∽�違�������с����⓾��������������

METHODS

  • new Math::BaseCalc

  • new Math::BaseCalc(digits=>...)

    ��違�������堺�域��膊���勉�с�������糸��鐚�荐恰絵鐚�Math::BaseCalc ��ŝ����吾�с�壔��鐚���� 篏���������障�����篏帥�����������絖���祉��������鐚���壔��������'0'��с�������������˩研��鴻��������鐚� ��ŝ�鴻����勉�ŝ����<�㋘�潟�鴻�������☗��臂í����������������������������������������⓾����� ���絖���祉��������篏帥��������������絎���с����障����� 鐚�緇������̹�≪����⓾�� digit() ��<�純��������荀���⓾��������������鐚�

    ��������������医����勉�祉��������-��勖��絖������˨����с����⓾�������医����勖�������勉�������激�ャ� 莢���勖�違��茵������障��������

  • $calc->to_base(NUMBER)

    ��医�ゃ��������腓冴�������⓾�������堺�違�������〠��絖������ц;�憗����������医�ゃ�後����������障�����

    NUMBER���Math::BigInt��ŝ����吾�с�壔����с�����to_base��壔����障����������� 罩g∈��ɾ�������勖��絖�������菴������с�����������

  • $calc->from_base(STRING)

    ���腓冴�������⓾�������堺�違�������〠��絖������ц;�憗����������医�ゃ�����Perl ��勖�贋�違� 紊���������障�����$calc ��勖��絖���祉�������������☗��臂í�������⓾����ŝ�����絖������� 筝���������������勖�壔����������壔��篁���壠��臂í�������⓾����障��������

    STRING���perl��勖�贋�域;�憗��絲障����☗ぇ��������������医�ゃ��紊���������������翫����� 腟������壩貴���絨���亥�鴻�勤;�憗�̬�ɱ��������紊������������������������������������勉�������� ��壚����勤��篌弱�ゃ�������������ŝ����勉�с��羂������ゃ����⓾��������������

  • $calc->digits

  • $calc->digits(...)

    ��糸��鐚�荐恰絵鐚�Math::BaseCalc ��ŝ����吾�с�壔��鐚���勖��絖���祉�������� get/set �����障����� 綣���亥�<����勐�翫����壔�������̥憜����勖��絖���祉��������罕�膀����������絖���勉�ŝ�鴻�����菴������障����� �憜����勖��絖���祉��������紊���眼�������������˨�壔����違��������絖���祉�������勉�ŝ�鴻����ŝ����<�㋘�潟�鴻����� ��ャ�������壔�������������������������������⓾��������絖���祉�������勐��������鐚�綣���違�������ㇱ�� 羝<����⓾�������������������������������������������⓾��������絖���祉�������勌��荀с�壩❶��勰�������с�����

    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)]);

    �����ŝ����勖��絖���祉��������茲���違�勖��絖���������c�⓾�������翫����勖�壔���������� �憜��絎�臂í�������⓾����障��������

QUESTIONS

'64' ������������絖���祉�������� Base64 膃☗垸�����綵鴻�̥����ゃ�◑�������⓾����障�������������壔�� MIME::Base64.pm ��≪�吾�ャ�若�˨�������������������障����������í����������障�����鐚� 腆冴�����絅�絋���������壩����c�⓾����障�����

AUTHOR

Ken Williams, ken@forum.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 modify it under the same terms as Perl itself.

SEE ALSO

perl(1).

膺肢┳��˨�ゃ����

膺肢┳���鐚�IWAI, Masaharu <iwaim.sub@gmail.com>

Perl�����㏍�ャ�<�潟����ユ�㋝��荐� Project ��˨�⓾�� Perl��≪�吾�ャ�若�˨�������㏍�ャ�<�潟����勛浸荐潟��茵���c�⓾�������障�����

http://sourceforge.jp/projects/perldocjp/
http://www.freeml.com/ctrl/html/MLInfoForm/perldocjp@freeml.com
http://perldoc.jp/