-
Notifications
You must be signed in to change notification settings - Fork 1
/
new
23 lines (20 loc) · 941 Bytes
/
new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static String leftShift(String bits, int positions) {
positions %= bits.length();
String rotated = bits.substring(positions) + bits.substring(0, positions);
return rotated;
}
public static String rightShift(String bits, int positions) {
positions %= bits.length();
String rotated = bits.substring(bits.length() - positions) + bits.substring(0, bits.length() - positions);
return rotated;
}
public static String leftCircShift(String bits, int positions) {
positions %= bits.length();
String rotated = bits.substring(positions) + bits.substring(0, positions);
return rotated;
}
public static String rightCircShift(String bits, int positions) {
positions %= bits.length();
String rotated = bits.substring(bits.length() - positions) + bits.substring(0, bits.length() - positions);
return rotated;
}