-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupportFunctions.java
More file actions
102 lines (82 loc) · 2.58 KB
/
SupportFunctions.java
File metadata and controls
102 lines (82 loc) · 2.58 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Scanner;
public class SupportFunctions {
static int[] ArrRev = new int[16];
public static int[] Reverse(int a[]) {
int[] out = new int[a.length];
int loop1 = 0;
while (loop1 < a.length) {
out[loop1] = a[a.length - loop1 - 1];
loop1++;
}
return out;
}
public void binaryInput() {
int input = getIntInput();
String s = Integer.toBinaryString(input);
String[] str = s.split("");
int size = str.length;
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = Integer.parseInt(str[i]);
}
int[] revBinary = Reverse(arr);
for (int i = 0; i < revBinary.length; i++){
ArrRev[i] = revBinary[i];
}
for (int i = ArrRev.length; i < 16; i++) {
ArrRev[i] = 0;
}
}
public int[] getBinary() {
return Reverse(ArrRev);
}
public static int[] getIntInput16() {
Scanner sc = new Scanner(System.in);
int[] array = new int[16];
System.out.println("Enter the elements of the array: ");
for (int i = 0; i < 16; i++) {
// reading array elements from the user
array[i] = sc.nextInt();
}
return array;
}
public static String getStringInput() {
Scanner sc = new Scanner(System.in);
String input = sc.next();
return input;
}
public static int getIntInput() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter value: ");
int userIn = sc.nextInt();
return userIn;
}
// This is the Finaly input function we gonna use for HardWareSimulation Input!
/**
* DEC-BIN Converter
*/
public int[] DbConv() {
// public static int[] bin;
System.out.println("Enter Value");
Scanner input = new Scanner(System.in);
int in = input.nextInt();
// String oout = toBinary(in);
// System.out.println(toBinary(in));
String temp = toBinary(in);
int[] numbers = new int[temp.length()];
for (int i = 0; i < temp.length(); i++) {
numbers[i] = temp.charAt(i) - '0';
}
return numbers;
}
public static String toBinary(int in) {
StringBuilder result = new StringBuilder();
for (int i = 31; i >= 0; i--) {
int mask = 1 << i;
result.append((in & mask) != 0 ? 1 : 0);
}
return result.toString();
}
}