A robust, command-line number base converter written in C.
This program converts 64-bit signed integers between any base from 2 to 36, using digits 0-9 and letters A-Z.
Built with a strong focus on memory safety, efficiency, and robust error handling.
- 🔄 Universal Base Support → Convert numbers between any base 2–36
- 🖥️ 64-Bit Integer Handling → Supports the full range of
long long(LLONG_MINtoLLONG_MAX) - 🚫 Robust Error Handling → Detects invalid inputs, empty strings, out-of-range bases, and overflow
- 📦 Dynamic Memory Management → No fixed-size buffers; input grows dynamically to any length
- 🛡️ Overflow Protection → Explicit checks prevent undefined behavior on large conversions
- ✅ Memory Safe → Every
malloc/reallochas a matchingfree, with zero leaks
- A C compiler (e.g., GCC or Clang)
Clone the repository:
git clone https://github.com/Samiul946/C-Number-Base-Converter.git
cd C-Number-Base-ConverterThis project takes a defensive approach to memory:
- Dynamic Input Buffers → Input grows automatically with
reallocas the user types, preventing overflow. After input, the buffer is shrunk to the exact required size. - Precise Output Allocation → Results are first calculated in a temporary stack buffer, then copied into a perfectly-sized heap allocation. No wasted memory, no risk of writing past bounds.
- Strict Ownership Model → Each heap allocation has a clear owner.
main()always frees what it allocates, ensuring zero leaks.
Special care is taken with edge cases like LLONG_MIN:
- Direct negation of
LLONG_MINis undefined behavior in C. - To avoid this, conversions use
unsigned long longintermediates. - This ensures correctness across the full signed 64-bit range.
- Invalid bases (
<2or>36) are rejected immediately - Non-digit/letter characters in input cause a graceful error
- Overflow during conversion is detected explicitly and reported
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.