Multiplication method

xiaoxiao2021-03-06  66

/ ************************************************** ************

* This program uses the granted method for multiplication

* Seeking 1011 * 1101

* CODER: Nine Day Shenlong

* operation result:

* H: / java / algorithm / big integer ~ 1> javac mult.java

*

* H: / java / algorithm / big integer ~ 1> java multi

* 11x13 Results: 143

*

* H: / java / algorithm / big integer ~ 1>

*********************************************************** ************ /

Import java.lang. *;

Class Mult {

Public int x, y; // This topic requires two numbers

/ / Initialize two numbers required in this question

MULT () {

X = 11; // binary 1011

Y = 13; // binary 1101

}

// ******************************************************** **

// Function name getValue, this function is the main function of this algorithm

// Reverse value is the product of the specified number xy

/ / According to formula XY = a * c * 2

N ((A-B) (D-C) AC BD) * 2

N / 2 BD

// A total of 3 multiplication, 6 plus method, 2 shift

// ******************************************************** **

Public Int GetValue (int A, int B, int C, int D) {

INT N = 4; // Number of scores

Return (A * C * (2 << (N-1))

((A-b) * (D-C) A * C B * D) *

(2 << (n / 2-1))

B * D);

}

Public static void main (String [] args) {

INT n = 2;

Mult mu = new mult ();

INT A, B, C, D;

// Decompose the original multiplier

A = MU.X >> N;

B = MU.X & 3;

C = MU.Y >> N;

D = MU.Y & 3;

int RET = MU.GETVALUE (A, B, C, D);

// Output Result

System.out.println (" MU.X " X " MU.Y " results are: " RET);

}

}

转载请注明原文地址:https://www.9cbs.com/read-86813.html

New Post(0)