Question

I m currently using the NTL to handle large integers. The large integers on this library are declared as ZZ. I would like to go from a ZZ number to a hexadecimal. However, NTL does not support conversion from ZZ to hexadecimals as I checked.

So my question is how can i go from ZZ (or maybe string which represent large decimal numbers) to hexadecimal forms? I prefer if it is possible to use the fascilities of this library to go directly to hex from ZZ if someone can help

Was it helpful?

Solution

Step1: The large number xx is taken initially as a string s

Step2: Say string s has length l then s=s[0]s[1]...s[l-1]. We read each character of s starting from position 0 and each time we convert this digit to an integer variable digit using int digit = atoi(ts.c_str()); Then we use the recursive relation value=10*value+digit where value is declared as ZZ and initialized to 0. After iterating through all digits we pass string to the ZZ value

Step3: Now to convert to hexadecimal form, using NTL we can compute modulo16 of ZZ numbers. So starting by value%2 and then computing (value-value%16)/16 and proceeding in this way we get the hex form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top