Skip to content

Commit a0c9134

Browse files
committed
feat: Creating a base number conversion package
1 parent 475ee12 commit a0c9134

19 files changed

Lines changed: 2813 additions & 1 deletion

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea/
2+
/vendor/

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM php:8.0
2+
3+
WORKDIR /usr/app
4+
5+
RUN \
6+
apt-get update ; \
7+
apt-get install -y --no-install-recommends \
8+
git \
9+
zip \
10+
unzip \
11+
sudo \
12+
; \
13+
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
14+
apt-get clean; \
15+
rm -rf /var/lib/apt/lists/* \
16+
; \
17+
\
18+
docker-php-ext-install bcmath \
19+
; \
20+
\
21+
useradd -m -s /bin/bash -u 1000 user ; \
22+
usermod -aG sudo user ; \
23+
\
24+
echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/user;
25+
26+
COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer
27+
28+
USER user

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# BaseConversion-php
1+
# BaseConversion-php
2+
3+
This is a simple PHP class to convert numbers from one base to another.
4+
5+
It provides methods to perform conversions between binary, decimal, and hexadecimal numbers. It can also perform conversions between arbitrary radix numbers.
6+
7+
## Installation
8+
9+
```bash
10+
composer require nave-wata/base-conversion
11+
```
12+
13+
## Usage
14+
15+
```php
16+
use NaveWata\BaseConversion\BaseConversion;
17+
18+
// Convert from binary
19+
BaseConversion::binaryToDecimal('1111'); // 15
20+
BaseConversion::binaryToHexadecimal('1111'); // F
21+
22+
// Convert from decimal
23+
BaseConversion::decimalToBinary('2'); // 10
24+
BaseConversion::decimalToHexadecimal('15'); // F
25+
26+
// Convert from hexadecimal
27+
BaseConversion::hexadecimalToBinary('F'); // 1111
28+
BaseConversion::hexadecimalToDecimal('F'); // 15
29+
30+
// Custom conversion
31+
$custom = new BaseConversion('abcdefghijklmnopqrstuvwxyz');
32+
33+
$custom->decimalToCustom('25'); // z
34+
$custom->customToDecimal('z'); // 25
35+
```

composer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nave-wata/base-conversion",
3+
"description": "This is a simple PHP class to convert numbers from one base to another.",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"NaveWata\\BaseConversion\\": "src/"
9+
}
10+
},
11+
"require": {
12+
"php": "8.*",
13+
"ext-bcmath": "*"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "^9.6"
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"NaveWata\\BaseConversion\\Tests\\": "tests/"
21+
}
22+
},
23+
"minimum-stability": "stable"
24+
}

0 commit comments

Comments
 (0)