-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplier.java
37 lines (31 loc) · 1010 Bytes
/
multiplier.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class multiplier
{
//Multiply
public static longword multiply(longword a, longword b) throws Exception
{
longword output = new longword();
int shiftcounter = 0;
for(int i = 31; i >= 0; i--)
{
bit andBit = b.getBit(i);
longword temp = new longword();
for(int j = 31; j >= 0; j--)
{
//Getting single value and then and-ing them with the whole of the second
temp.setBit(j, a.getBit(j).and(andBit));
}
if(shiftcounter != 0)
{
//leftShifting based on where location of and bit is
longword shifted = temp.leftShift(shiftcounter);
output = rippleAdder.add(output, shifted);
}
else
{
output = rippleAdder.add(output, temp);
}
shiftcounter++;
}
return output;
}
}