<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt">Sorry, I am not explaining myself well. What we have is not a vector containing the characters (i.e. ascii) representing a number, but the actual hex bytes. For example, we might have a 4 byte array containing [0x31 0x32 0x33 0x34]. For us this is NOT the number "1234" but the number 0x31323334 or in decimal 825373492. I supposed we should have used the name vector<unsigned short> but someone used vector<char> which is a bit misleading.<br>Thanks, Bob<br><div> </div><font style="color: rgb(127, 0, 63);" size="3"><span style="font-style: italic;"></span></font><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 13px;">----- Original Message ----<br>From:
Marc Glisse <marc.glisse@normalesup.org><br>To: Robert Evans <bobsphysics@yahoo.com><br>Cc: gmp-discuss@swox.com<br>Sent: Wednesday, August 13, 2008 12:38:49 PM<br>Subject: Re: Construction From vector<char> ?<br><br>
On Wed, 13 Aug 2008, Robert Evans wrote:<br><br>> Also very useful for me would be the output of an mpz_class object into<br>> an array (vector<char>). Perhaps there is a way to do this via the<br>> ostream operators? My basic problem is: we are already using byte<br>> arrays which represent trans-64 bit numbers. I could do a HUGE amount of<br>> refactoring of really bad code which manipulates such arrays if I could<br>> construct a mpz_class from such an array, do the arithmetic within GMP,<br>> output back into an array. The C++ interface seems to character-based<br>> I/O only.<br><br>I am having a hard time understanding what you say. You are complaining <br>that the interface is character-based and you would like something that <br>interacts better with a vector of characters...<br><br>If as I believe your vector<char> is just a string with a silly name, the <br>conversions are
pretty trivial, and I gave you two ways (there are many <br>others) to go from vector<char> to string. The reverse direction is just <br>as easy.<br><br>The only other thing your vector could be is like a gmp representation <br>with 8-bit limbs, which sounds very strange so I am not considering it.<br><br>If you think the conversions include too many copies, you can use the <br>mpn_set_str function for instance, that takes a char* and a length instead <br>of expecting a null char to mark the end. But beware that you need to deal <br>with the allocations yourself then.<br><br>-- <br>Marc Glisse<br></div></div></div><br>
</body></html>