View Single Post
Old 2021-11-25, 15:46   #1
hunson
 
Feb 2020
Germany

2·52 Posts
Default Init GMP variable with char or bit shift?

Hi,


I started learning C a couple of days ago and thought it might be fun to make use of the speed of C and learn the language with an 'useful' application: calculating with GMP.
I played around with some functions and thought it might be fun to generate huge solinas numbers (2^a +/- 2^b +/-1).

I calculated the 2^x terms with mpz_pow_ui() individually and added them. This works fine so far. Then I realized that these numbers have a special form in base 2 (e.g. 2^10+2^6-1 = 10000111111). So they might be generated way faster by bit shifting or construction of a 'bit' char/string than doing the mpz_pow_ui() calculations for large exponents.



Now my questions is: Is there a way to import/convert a char into a mpz_t variable for further calculation? I tried mzp_set_str() base 2 but I can not make it work if I construct the char variable with a loop. A predefined variable like char *num = "10000000000"; gives the correct number of 1024, but no further manipulation is possible.

Any help or pointing in the right direction is very much appreciated.



hunsun
hunson is offline   Reply With Quote