Translate a number from any numerical system into any numerical system 🔢
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Daniel Santos c2aa9254a4 update .gitignore 2 months ago
doc@f5ca8047d9 update 6 months ago
tests test rule in Makefile 7 months ago
.gitignore update .gitignore 2 months ago
.gitmodules add submodule doc/ 7 months ago
Doxyfile rename doxygen.conf to Doxyfile 7 months ago
LICENSE add MIT license 7 months ago
Makefile Makefile: include header file in install-lib 7 months ago update 6 months ago
cli.c cli.c: usage with argv[0] 5 months ago
html add html symlink for doxygen build 7 months ago
numericx.c move between files numeral_ptr struct 7 months ago
numericx.h move between files numeral_ptr struct 7 months ago

Numericx Readme

A program that converts a number (or text) from one numerical system into another different numerical system.

C library

Create libraries

You may use make libs to create a static and a shared numericx library. To install a shared library into your system use sudo make prefix=/usr install-lib.


See Numericx documentation website, for the list of functions and function arguments of the Numericx library. Look at Files > File List in the documentation menubar website.

There are basically two main functions: the numericx_translate() and the numericx_free(). Remember to free your numericx result with numericx_free(var);!

Code example

Look at the cli.c file for an example of how to call Numericx in your C program.

Here is a code snippet:


/* 'result' variable has to be NULL */
char* result = NULL;

 * 'from', 'to' and 'number' are strings (malloced or literals, not arrays).
 * the rest of the variables, except 'result', are booleans
 * Do the translation
int status = numericx_translate(
		from_numericals, from_units_on_the_end, from_first_number_void, from_infinite_base,
		to_numericals, to_units_on_the_end, to_first_number_void, to_infinite_base,
		number, &result);

/* Test for translation failure */
switch( status )
	case EINVAL:
		fprintf(stderr, "error: numericx: %s. Resulting string argument value has to be NULL.\n",
	case EDOM:
		fprintf(stderr, "error: numericx: %s. Valid numerals are: \"%s\".\n",
				strerror(EDOM), from);
	case ERANGE:
		fprintf(stderr, "error: numericx: Unrepresentable void number.\n");

/* General error message with free and exit() */
if( !(status == true) )
	fprintf(stderr, "error: numericx: Incapable of translating.\n");


/* Print translated number ('result') in case of success */
printf("%s\n", result);

/* Free translated number, when no longer needed */




With this program, you can create an executable (or many) that will convert a number from one numerical system into another one. This is good if, for example, you want to use numerical system translation with your bash terminal.

For example, you may want to convert a hexadecimal number into a ternary number. Here is what you would do.

You first need to define the proprieties of the numerical systems. These proprieties are defined in the compilation process (as compilation flags).

For example, let's make the hexdecimal numerical system with numerals from 0-f, with a infinite 0 and it start counting on 1. So, our hexadecimal system will need the following compilation flags:


if you want the units place of this numerical system to be on the right side, add -DFROM_UNITS_ON_THE_END.

Now, for the ternary system let's make with numerals from 1-3, 1 is not infinite and it start counting on 1. Use this flags:


if you want the units place of this numerical system to be on the right side, use -DTO_UNITS_ON_THE_END.

Now, to create the executable to translate a number for these two numerical system, join all of this together and compile using this:


This creates the hex-to-ternary executable with can be used to convert numbers from hexadecimal to ternary!

Pre-defined executable compilation

There are many pre-defined compilation of executables on the Makefile. Take a look at the Makefile to know them. Or you can run make to get all of the pre-defined executables. make clean to delete them.

Compilation flags meanings

There are two categories for the compilation flags: the FROM category and the TO category.

FROM flags are the numerical system definitions of the argument number.

TO flags are the numerical system definitions of the number result.

Below, are the meanings of the FROM flags. The TO flags are the same as the FROM flags, with a switch of the FROM_ to a TO_.

Flag Meaning
FROM_NUMERICALS Define the numerical system numerals of the 'from'
FROM_UNITS_ON_THE_END Defines the units case to be on the end (on the right) for the 'from'
FROM_FIRST_NUMBER_VOID Defines the first number as a "not counting" for the 'from'
FROM_INFINITE_BASE Defines the first number to be infinite, for the 'from' (for example, if the first numeral is 0, then 0 == 00 == 000 == 0000 ... . Or if the first numeral is 1, then 1 == 11 == 111 ...)

Remember: you use put a -D before these flags names as an compiler argument. For example, -DFROM_NUMERICALS=....




Daniel A. C. Santos