Name
Encode::Positive::Digits - Encode a positive integer using the specified digits and vice-versa
Synopsis
ok 101 == Encode::Positive::Digits::encode(
"5"
,
"01"
);
ok 5 == Encode::Positive::Digits::decode(
"101"
,
"01"
);
ok
"hello world"
eq Encode::Positive::Digits::encode(4830138323689,
" abcdefghlopqrw"
);
ok 4830138323689 == Encode::Positive::Digits::decode(
"hello world"
,
" abcdefghlopqrw"
);
The numbers to be encoded or decoded can be much greater than 2**64 via support from Math::BigInt, such numbers should be placed inside strings to avoid inadvertent truncation.
my
$n
=
'1'
.(
'0'
x999).
'1'
;
my
$d
= Encode::Positive::Digits::decode(
$n
,
"01"
);
my
$e
= Encode::Positive::Digits::encode(
$d
,
"01"
);
ok
$n
==
$e
ok
length
(
$d
) == 302;
ok
length
(
$e
) == 1001;
ok
length
(
$n
) == 1001;
Description
Encode and decode
encode
Returns a string which expresses a positive integer in decimal notation as a string using the specified digits. The specified digits can be any characters chosen from the Unicode character set.
1
$number
Decimal integer
2
$digits
Encoding digits
decode
Return the integer expressed in decimal notation corresponding to the value of the specified string considered as a number over the specified digits
1
$number
Number to decode
2
$digits
Encoding digits
Index
Installation
This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.
Standard Module::Build process for building and installing modules:
perl Build.PL
./Build
./Build test
./Build install
Author
Copyright
Copyright (c) 2016-2017 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.