Wrong result after mpz_mul_2exp

Sebastian Schucht sschucht at fbihome.de
Wed Oct 31 20:25:39 CET 2007


Hallo together,

I've written some code and get some misteryos error. I'm shift the word 
0x87654321 once to the left. But then I'm geting  the result 0x0ECb8642 
instead of 0x0ECa8642. The following code is an minimal exsample for the 
problem. With all other words I try it works fine.

#include <iostream>
#include <iomanip>
#include <gmp.h>

using namespace std;

int main(int argc, char* argv[])
{
	mpz_t lmpz_A;
	unsigned int luip_Data[2] = {0x00000002, 0x87654321};
	unsigned int lui_Nr=0;

	mpz_init(lmpz_A);

	mpz_import (lmpz_A, 1, 1, sizeof(unsigned int), 1, 0, &luip_Data[1]);
	mpz_mul_2exp(lmpz_A, lmpz_A, 1);
	
	mpz_export (luip_Data, &lui_Nr , 1, sizeof(unsigned int), 1, 0, lmpz_A);
	
	for(unsigned int i=0; i<lui_Nr; i++)
		cout<<hex<<setw(8)<<setfill('0')<<luip_Data[i]<<" ";
	cout<<endl;
	
	return EXIT_SUCCESS;
}

- Are there any errors in my code?
- Did I have any mistake in mycalculations?
- or is this a bug?

Thanks for your attention!

Sebastian Schucht

-- 
B.Sc. Sebastian Schucht
Teichhausstraße 38
64287 Darmstadt

+49 176 20139739
UIN: 260 121 043
skype: SebastianSchucht
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20071031/a9d3a0cb/attachment.bin 


More information about the gmp-discuss mailing list