Powerful math base numbers operations library for Android developers. This library can convert a number between two custom bases (between 2 and 62). It works with String, so theoretically, the number limit is infinite :). The library supports large/huge numbers in each math base.
Common bases: base 2, base 8, base 10, base 16. Examples:
3424(10) = 110101100000(2)
12623(10) = 314f(16)
3a4f(16) = 11101001001111(2)
Sample app available from the play store.
Download via Maven:
<dependency>
<groupId>ro.mdc_software</groupId>
<artifactId>basenumber</artifactId>
<version>0.3</version>
</dependency>
Download via Gradle:
Step 1. Add the repositories into your build.gradle
repositories {
jcenter()
maven {
url "http://dl.bintray.com/cosminmihu/android"
}
}
Step 2. Add the dependency in the form
dependencies {
compile 'ro.mdc_software:basenumber:0.3'
}
Download via Ivy:
<dependency org='ro.mdc_software' name='basenumber' rev='0.3'>
<artifact name='basenumber' ext='pom' />
</dependency>
Already defined BaseNumbers:
BaseNumber.ZERO;
BaseNumber.ONE;
Base Systems
Base 2 - digits: 01
Base 3 - digits: 012
Base 4 - digits: 0123
Base 8 - digits: 01234567
Base 10 - digits: 0123456789
Base 16 - digits: 0123456789ABCDEF
....
Base 32 - digits: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Base 62 - digits: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Create new BaseNumber: ADD
BaseNumber nbr_0_10 = BaseNumber.ZERO;
BaseNumber nbr_0_10 = new BaseNumber();
BaseNumber nbr_0_10 = new BaseNumber(0);
BaseNumber nbr_0_10 = new BaseNumber("0");
BaseNumber nbr_0_10 = new BaseNumber(0, 10);
BaseNumber nbr_0_10 = new BaseNumber("0", 10);
BaseNumber nbr_1_10 = BaseNumber.ONE;
BaseNumber nbr_1_10 = new BaseNumber(1);
BaseNumber nbr_1_10 = new BaseNumber("1");
BaseNumber nbr_1_10 = new BaseNumber(1, 10);
BaseNumber nbr_1_10 = new BaseNumber("1", 10);
BaseNumber nbr_EF1_16 = new BaseNumber("EF1", 16);
Operation: ADD
BaseNumber nbr_234_10 = new BaseNumber(234, 10);
BaseNumber nbr_23_10 = new BaseNumber(23, 10);
BaseNumber total = nbr_234_10.add(nbr_23_10));
Log.d("TOTAL", total.toString()); // 257(10)
BaseNumber nbr_A102F_16 = new BaseNumber("A102F", 16);
BaseNumber nbr_23_16 = new BaseNumber(23, 16);
BaseNumber total = nbr_A102F_16.add(nbr_23_16));
Log.d("TOTAL", total.toString()); // A1052(16)
Operation: SUB
BaseNumber nbr_234_10 = new BaseNumber(234, 10);
BaseNumber nbr_23_10 = new BaseNumber(23, 10);
BaseNumber total = nbr_234_10.sub(nbr_23_10));
Log.d("TOTAL", total.toString()); // 211(10)
BaseNumber nbr_A102F_16 = new BaseNumber("A102F", 16);
BaseNumber nbr_23_16 = new BaseNumber(23, 16);
BaseNumber total = nbr_A102F_16.sub(nbr_23_16));
Log.d("TOTAL", total.toString()); // A100C(16)
Operation: MUL
BaseNumber nbr_234_10 = new BaseNumber(234, 10);
BaseNumber nbr_23_10 = new BaseNumber(23, 10);
BaseNumber total = nbr_234_10.mul(nbr_23_10));
Log.d("TOTAL", total.toString()); // 5382(10)
BaseNumber nbr_EA_16 = new BaseNumber("EA", 16);
BaseNumber nbr_17_16 = new BaseNumber(17, 16);
BaseNumber total = nbr_EA_16.mul(nbr_17_16));
Log.d("TOTAL", total.toString()); // 1506(16)
Operation: DIV
BaseNumber nbr_5382_10 = new BaseNumber(5382, 10);
BaseNumber nbr_23_10 = new BaseNumber(23, 10);
BaseNumber total = nbr_5382_10.div(nbr_23_10));
Log.d("TOTAL", total.toString()); // 234(10)
BaseNumber nbr_1506_16 = new BaseNumber(1506, 16);
BaseNumber nbr_17_16 = new BaseNumber(17, 16);
BaseNumber total = nbr_1506_16.div(nbr_17_16));
Log.d("TOTAL", total.toString()); // EA(16)
Operation: MODULO
BaseNumber nbr_5382_10 = new BaseNumber(53822, 10);
BaseNumber nbr_23_10 = new BaseNumber(23, 10);
BaseNumber total = nbr_5382_10.modulo(nbr_23_10));
Log.d("TOTAL", total.toString()); // 2(10)
BaseNumber nbr_EA4F_16 = new BaseNumber("EA4F", 16);
BaseNumber nbr_17_16 = new BaseNumber(17, 16);
BaseNumber total = nbr_EA4F_16.modulo(nbr_17_16));
Log.d("TOTAL", total.toString()); // 16(16)
Operation: TBD
Android 2.3+ (API Level 9)
Copyright 2016 Dumitru-Cosmin Mihu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.