-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword.java
More file actions
64 lines (57 loc) · 1.52 KB
/
Copy pathword.java
File metadata and controls
64 lines (57 loc) · 1.52 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
public class word {
public boolean[] value;
/*
* Constructors to handle different inputs for creating a word object
*/
public word(){
value = new boolean[16];
}
public word(String s){
value = new boolean[16];
if(s.length() == 16){
for(int i = 0; i<16; i++){
if(s.charAt(i) == '0')
value[i] = false;
else
value[i] = true;
}
}
else if(s.length() < 16){
boolean[] bin = operational.binaryStringToBinary(s);
int pos = 15;
for(int i = bin.length-1; i>=0; i--){
value[pos] = bin[i];
pos--;
}
}
}
public word(boolean[] a){
value = new boolean[16];
if(a.length == 16)
for(int i = 0; i<16; i++)
value[i] = a[i];
}
/*
* Prints out the string of the word
*/
public String toString(){
String val = "";
for(int i = 0; i<value.length; i++)
val += (value[i] ? 1 : 0);
return val;
}
/*
* Returns boolean array representation of word
*/
public boolean[] toBitArray(){
return value;
}
/*
* Deeply replaces the word
*/
public void overWrite(word replacement){
boolean[] replace = replacement.toBitArray();
for(int i = 0; i<16; i++)
value[i] = replace[i];
}
}