Multiplying java ints, and dropping edx in the process

From dftwiki3
Jump to: navigation, search

--D. Thiebaut (talk) 13:30, 7 November 2014 (EST)




Java Program Multiplying two Ints


import java.math.BigInteger;


public class JavaLimits {

	public static void main(String[] args) {
		// -----------------------------------------------
		// a multiplication of ints
		int x = 0x30000001;
		int y = 0x30000001;

		System.out.println( "x = " + x );
		System.out.println( "y = " + y );
		
		int z = x * y;

		System.out.println( "z = " + z );
		System.out.println();
		
		// -----------------------------------------------
		// a multiplication of BigIntegers
		BigInteger xx, yy, zz;
		xx = BigInteger.valueOf( x );
		yy = BigInteger.valueOf( y );
		
		System.out.println( "xx = " + xx );
		System.out.println( "yy = " + yy );
		
		zz = xx.multiply( yy );

		System.out.println( "zz = " + zz );
	}
}


Output


x = 805306369
y = 805306369
z = 1610612737

xx = 805306369
yy = 805306369
zz = 648518347951964161