-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShifter.java
More file actions
41 lines (40 loc) · 1.2 KB
/
Shifter.java
File metadata and controls
41 lines (40 loc) · 1.2 KB
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
38
39
40
41
public class Shifter {
public static void LeftShift(Word32 source, int amount, Word32 result) {
int i = 0;
Word32 sourceCopy = new Word32();
source.copy(sourceCopy);
while(i < amount){
for(int n = 0; n < 32; n++){
if(n < 31){
Bit b = new Bit(false);
sourceCopy.getBitN(n+1, b);
result.setBitN(n, b);
}
else
result.setBitN(31, new Bit(false));
}
sourceCopy = result;
i++;
}
if(amount == 0)
source.copy(result);
}
public static void RightShift(Word32 source, int amount, Word32 result) {
int i = 0;
Word32 sourceCopy = new Word32();
source.copy(sourceCopy);
while(i < amount){
for(int n = 31; n > 0; n--){
if(n > 0){
Bit b = new Bit(false);
sourceCopy.getBitN(n-1, b);
result.setBitN(n, b);
}
else
result.setBitN(0, new Bit(false));
}
sourceCopy = result;
i++;
}
}
}