This Go module provides command-line utilities for converting between hexadecimal and decimal numbers.
- Clone the repository:
git clone https://github.com/jenish-rudani/hexdec-converter.git
cd hexdec-converter- Build the binaries:
make- Install the utilities to your system PATH:
make installNote: The make install command may require sudo privileges on Linux and macOS. On Windows, you may need to run your terminal as Administrator.
After installation, you can use the utilities from anywhere in your terminal:
Convert hexadecimal to decimal:
h2d <hexadecimal number>Convert decimal to hexadecimal:
d2h <decimal number>Here are some examples of how to use the utilities:
-
Hexadecimal to Decimal:
$ h2d A 10 $ h2d FF 255 $ h2d 100 256
-
Decimal to Hexadecimal:
$ d2h 10 A $ d2h 255 FF $ d2h 256 100
To build binaries for multiple platforms:
makeThis will create binaries in the binary directory, organized by platform.
To run the unit and integration tests:
make testThis will run tests for the converter package and integration tests for the command-line tools.
hexdec-converter/
├── cmd/
│ ├── h2d/
│ │ └── main.go
│ └── d2h/
│ └── main.go
├── pkg/
│ └── converter/
│ ├── converter.go
│ └── converter_test.go
├── test/
│ └── integration_test.go
├── Makefile
├── go.mod
└── README.md
cmd/: Contains the main applications for h2d and d2h.pkg/: Contains the core logic for conversion in the converter package.test/: Contains integration tests for the command-line tools.
The project includes a Makefile with the following commands:
make: Build the binaries for all supported platformsmake test: Run unit and integration testsmake clean: Remove all generated binariesmake info: Display usage information and examplesmake install: Install the utilities to your system PATH
To view the usage information and examples in the terminal, run:
make infoThis will display:
Hexadecimal-Decimal Converter
Usage:
h2d <hexadecimal number> - Convert hex to decimal
d2h <decimal number> - Convert decimal to hex
Examples:
h2d FF -> 255
d2h 255 -> FF
Build: make
Test: make test
Clean: make clean
Install: make install
Contributions are welcome! Please feel free to submit a Pull Request.
GNU General Public License v3.0
See License file for more details