Hex2Dec is a simple yet powerful hexadecimal (HEX) to decimal (DEC) converter.
$$\ $$\ $$$$$$$$\ $$\ $$\ $$$$$$\ $$$$$$$\ $$$$$$$$\ $$$$$$\
$$ | $$ |$$ _____|$$ | $$ |$$ __$$\ $$ __$$\ $$ _____|$$ __$$\
$$ | $$ |$$ | \$$\ $$ |\__/ $$ |$$ | $$ |$$ | $$ / \__|
$$$$$$$$ |$$$$$\ \$$$$ / $$$$$$ |$$ | $$ |$$$$$\ $$ |
$$ __$$ |$$ __| $$ $$< $$ ____/ $$ | $$ |$$ __| $$ |
$$ | $$ |$$ | $$ /\$$\ $$ | $$ | $$ |$$ | $$ | $$\
$$ | $$ |$$$$$$$$\ $$ / $$ |$$$$$$$$\ $$$$$$$ |$$$$$$$$\ \$$$$$$ |
\__| \__|\________|\__| \__|\________|\_______/ \________| \______/
π οΈ HEX to DEC Converter
π Contents
- Application
- Use?
- Installation
- Usage
- Documentation
- Tools
- Bugs
- Author
- Code
- Code Functionality Description
- Page
- Summary
- Disclaimer
- Download
- License
π Application
HEX to DEC Converter is a simple but powerful command line tool written in Golang that converts hexadecimal (HEX) values to decimal values ββ(DEC). Supports both single HEX values ββand batch processing from a file. The tool is intended for programmers, engineers and anyone working with numerical systems.
π Main features:
- β Convert single HEX values ββto DEC.
- β Process multiple HEX values ββfrom a file.
- β Saving results to an output file.
- β Easy-to-use command line interface.
- β Lightweight and fast.
- β Runs in the console (CMD/CLI).
π‘ Use
π€ Automation:
The program eliminates the need to manually convert HEX values ββto DEC, which saves time and reduces the risk of errors.
ποΈ Flexibility:
Supports both single values ββand files with multiple HEX values.
π οΈ Simplicity:
Ease of use with a clean text interface and flag support.
π Security:
Includes error handling for invalid input.
π₯ Installation
Prerequisites
- Go (Golang) installed on your system. You can download it here.
Steps
- Clone the repository:
git clone https://github.com/lukaszwojcikdev/hex2dec_converter.git
- Go to the project directory:
cd hex2dec_converter
- Build the project:
go build -o hex2dec_converter
or
go build hex2dec_converter.go
- Run the executable:
./hex2dec_converter
π οΈ Usage
Convert a single HEX value
To convert a single HEX value to DEC, use -dh flag:
./hex2dec_converter -dh 583DFD
Output:
5787133
Convert HEX values ββfrom file
To convert multiple HEX values ββfrom file, use the -dhf flag:
./hex2dec_converter -dhf input.txt
-
Input file format: HEX values ββshould be separated by commas (
,), e.g.108AB2,1BBBFE,6386DE. -
Output: The results will be written to a file named
input_dec.txt.
Show help
To show the help menu, use the -h flag:
./hex2dec_converter -h
Show program information
To show program information, use the -i flag:
./hex2dec_converter -i
π Documentation
Flags:
-h - Show help.
-i - Show program information.
-dh - Convert a single HEX value to DEC.
-dhf - Convert HEX values ββfrom a file to DEC and save the result to a new file.
Input file format:
HEX values ββin the file should be separated by commas (,) without spaces.
Example:
108AB2,1BBBFE,6386DE
For detailed documentation, visit the official project website:
https://lukaszwojcik.eu/hex2dec.html
π οΈ Tools
During the development of HEX2DEC and the creation of this README.md file, I used the following tools and software:
- IrfanView - Used to resize images.
- TinyPNG - Used to compress images to reduce file size without losing quality.
- Notepad++ - Code editor used to write the project.
- Go (Golang) - The basic programming language used to develop the HEX2DEC converter.
- Carbon - Used to create beautiful source code syntax as a PNG image.
- GitHub - Used for version control and hosting the project repository.
- MD5 - Used to generate an MD5 hash file.
- ASCII Generator - Used to create an ASCII logo for the project.
-
Shields.io - Used to generate badges for the
README.mdfile (e.g. version, license, etc.). -
Markdown Online - Used to write and format the
README.mdfile. - Unicode Icons - Unicode icon set used for ## or ### paragraphs.
- Stable Diffusion - Used to generate the cover image.
- π΅ Music by ZHU - Relaxing music listened to while designing Hex2Dec.
π Bugs
If you encounter any bugs or issues, please report them here
π¨β Author
- Εukasz WΓ³jcik
- π Website: https://lukaszwojcik.eu
- π LinkedIn: https://www.linkedin.com/in/lukasz-michal-wojcik
βπ» Source code
packagemain
import (
"flag"
"fmt"
"log"
"axis"
"strconv"
"strings"
)
func hexToDec(hex string)(string, error) {
dec, err := strconv.ParseInt(hex, 16, 64)
if err != nil {
return "", fmt.Erorf("Invalid HEX value: %s", hex)
}
return strconv.FormatInt(dec, 10), nil
}
func hexToDecFile(fileName string) error {
data, err := os.ReadFile(fileName)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
hexValues ββ:= strings.Split(strings.TrimSpace(string(data)), ","")
var decValues ββ[]string
for _, hex := range hexValues ββ{
dec, err := hexToDec(hex)
if err != nil {
return fmt.Errorf("conversion error: %w", err)
}
decValues ββ= append(decValues, dec)
}
outputFileName := strings.TrimSuffix(fileName, ".txt") + "_dec.txt"
outputData := []byte(strings.Join(decValues, ","))
err = os.WriteFile(outputFileName, outputData, 0644)
if err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
func printHelp() {
fmt.Println("HEX to DEC Converter v1.0c")
fmt.Println("ββββββββββββββββββββββββββββ")
fmt.Println("ββββββββββββββββββββββββββββ")
fmt.Println("ββββββββββββββββββββββββββββ")
fmt.Println("")
fmt.Println("(c) by Lukasz Wojcik 2024, 2025")
fmt.Println("Use: hex2dec [flag] [argument]")
fmt.Println("")
fmt.Println("Flags:")
fmt.Println(" -h Display help")
fmt.Println(" -i Displays program information")
fmt.Println(" -dh Converts a HEX value to DEC ")
fmt.Println(" -dhf Converts HEX values ββfrom file and writes DEC to file")
fmt.Println("")
fmt.Println("Examples of use:")
fmt.Println(" hex2dec -dh 583DFD")
fmt.Println(" hex2dec -dhf input.txt")
fmt.Println("")
fmt.Println("HEX values ββin the file should be separated by a comma (,) with no 'space'.")
fmt.Println("Example of the HEX system arrangement in the 'inside.txt' file:")
fmt.Println("108AB2,1BBBFE,6386DE,...,...")
}
func printProgramInfo() {
fmt.Println("Hex2Dec - HEX to DEC Converter")
fmt.Println("Author: Lukasz Wojcik")
fmt.Println("Version: 1.0c")
fmt.Println("Year: 2025")
fmt.Println("Site: https://lukaszwojcik.eu/hex2dec.html")
fmt.Println("Source Code: https://github.com/lukaszwojcikdev/hex2dec_converter.git")
}
func main() {
convertHex := flag.String("dh", "", "Converts HEX value to DEC")
help := flag.Bool("h", false, "Displays help")
info := flag.Bool("i", false, "Displays information about the program")
convertHexFile := flag.String("dhf", "", "Converts HEX values ββfrom a file and writes DEC to the file")
flag.Parse()
if *help {
printHelp()
return
}
if *info {
printProgramInfo()
return
}
if *convertHex != "" {
dec, err := hexToDec(*convertHex)
if err != nil {
log.Fatal(err)
}
fmt.Println(dec)
return
}
if *convertHexFile != "" {
err := hexToDecFile(*convertHexFile)
if err != nil {
log.Fatal(err)
}
fmt.Println("Conversion completed successfully. Results saved to file: input_dec.txt")
return
}
printHelp()
}
π Description
-
hexToDecFunction converts a single HEX value to DEC.
func hexToDec(hex string) (string, error) {
dec, err := strconv.ParseInt(hex, 16, 64)
if err != nil {
return "", fmt.Errorf("Invalid HEX value: %s", hex)
}
return strconv.FormatInt(dec, 10), nil
}
Parameters:
hex: a string representing a hexadecimal number.
Returns:
A decimal value as a string.
Error if the HEX value is invalid.
Action:
Uses strconv.ParseInt function to convert HEX to DEC.
If an error occurs, it returns an appropriate message.
-
hexToDecFileThe function converts HEX values ββstored in a file to DEC values ββand writes the result to a new file.
func hexToDecFile(fileName string) error {
data, err := os.ReadFile(fileName)
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
hexValues ββ:= strings.Split(strings.TrimSpace(string(data)), ","")
var decValues ββ[]string
for _, hex := range hexValues ββ{
dec, err := hexToDec(hex)
if err != nil {
return fmt.Errorf("conversion error: %w", err)
}
decValues ββ= append(decValues, dec)
}
outputFileName := strings.TrimSuffix(fileName, ".txt") + "_dec.txt"
outputData := []byte(strings.Join(decValues, ","))
err = os.WriteFile(outputFileName, outputData, 0644)
if err != nil {
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
Parameters:
fileName: the name of the input file containing HEX values, separated by commas.
Returns:
error: error if the read, convert or write operation fails.
Action:
Reads the contents of the file.
Separates the HEX values ββby commas.
Converts any HEX value to DEC using the hexToDec function.
Saves the results to a new file named filename_dec.txt.
-
printHelpThe function displays help for the user.
func printHelp() {
fmt.Println("HEX to DEC Converter v1.0c")
...
}
What it does:
Displays detailed information about available flags, arguments, and examples of program usage. It tells you what the input data in the file should look like.
-
printProgramInfoThe function displays information about the program.
func printProgramInfo() {
fmt.Println("Hex2Dec - HEX to DEC Converter")
...
}
Action:
Displays the program name, author, version, year of release, and links to the source code page and repository.
-
mainThe main function of the program, handling control logic based on flags passed by the user.
func main() {
convertHex := flag.String("dh", "", "Converts HEX value to DEC")
help := flag.Bool("h", false, "Displays help")
info := flag.Bool("i", false, "Displays information about the program")
convertHexFile := flag.String("dhf", "", "Converts HEX values ββfrom a file and writes DEC to the file")
flag.Parse()
if *help {
printHelp()
return
}
if *info {
printProgramInfo()
return
}
if *convertHex != "" {
dec, err := hexToDec(*convertHex)
if err != nil {
log.Fatal(err)
}
fmt.Println(dec)
return
}
if *convertHexFile != "" {
err := hexToDecFile(*convertHexFile)
if err != nil {
log.Fatal(err)
}
fmt.Println("Conversion completed successfully. Results saved to file: input_dec.txt")
return
}
printHelp()
}
Operation:
Defines flags:
-dh: converts a single HEX value to DEC.
-h: prints help (printHelp).
-i: prints program information (printProgramInfo).
-dhf: converts HEX values ββfrom a file to DEC and writes them to a file.
Based on the given flags, performs the appropriate operations:
β‘οΈDisplays help or program information.
β‘οΈConverts a single HEX value to DEC.
β‘οΈProcesses a file with HEX values.
If no flag is given, prints help.
π Summary
HEX to DEC Converter is a versatile tool for converting hexadecimal values ββto decimal values. It is designed to be simple, powerful and easy to use, making it ideal for programmers, engineers and students working with number systems.
β οΈ Disclaimer
By using this software, you agree to these terms. The software is provided βas isβ and you use it at your own risk. The author is not responsible for any damages or problems caused by using this software.
π₯ Download
You can download the latest version of the project HERE π
| Download |
|---|
| Hex2Dec.zip |
| Source_Code |
| MD5 |
| Carbon |
π License
This project is licensed under the MIT License
Enjoy using the HEX to DEC converter! π
Top comments (0)