
class myByte{
//this class represents my version of a byte
//It contains an array of 8 booleans and provides
//methods as required

//bytes[0] is the LSB, bytes[7] is the MSB
public boolean [] bytes;
//this array holds the boolean values
//it is public so that they can be accessed
//directly without accessor methods.

//an simple constructor which initialises the array
public myByte(){
	bytes = new boolean[8];
}

// a constructor that takes in 8 boolean values. the first value is the MSB etc.
public myByte(boolean a, boolean b, boolean c, boolean d, boolean e, boolean f, boolean g, boolean h) {
	bytes = new boolean[8];
	bytes[7] = a;
	bytes[6] = b;
	bytes[5] = c;
	bytes[4] = d;
	bytes[3] = e;
	bytes[2] = f;
	bytes[1] = g;
	bytes[0] = h;
}

//a constructor that takes an int and converts it to a myByte object by filling
//the array as required with 1 or 0
public myByte(int a){
   bytes = new boolean[8];
 	int temp = a;
	for(int i = 0; i<8;i++){
		if( (temp % 2) == 1 ) {
			bytes[i] = true;
		} else {
			bytes[i] = false;
		}
 	   temp = temp / 2;
	}
}

//this methods takes in a myByte object and returns the result
//of it being XORed with the current myByte object
//it uses a private method called intXOR. It doesn't actually effect 
//the current myByte object
public myByte XOR(myByte b){
	myByte temp = new myByte();
	for(int i = 0; i<8;i++){
		temp.bytes[i] = intXOR(bytes[i], b.bytes[i]);
	}
	return temp;
}

//this private method is used by XOR to return
//the results of the XOR operation on a single bit
private boolean intXOR(boolean a, boolean b){
	boolean temp = false;
	if( ((a== true) && (b == false)) || ((b == true) && (a == false))) {
		temp = true;
	}
	return temp;
}

//this constructor takes in a string containing 1's and 0's
//the first bit in the string is the MSB
public myByte(String a){
	bytes = new boolean[8];
	String s;
	Character c;
	for(int i = 0;i<8;i++){
		c = new Character(a.charAt(i));
		s = c.toString();
		if(s.equals("1")){
	 		bytes[7-i] = true;
		} else {
			bytes[7-i] = false;
		}
	}
}

//a constructor that takes in a boolean array
public myByte(boolean b[]) {
	bytes = b;
}

//this method returns an decimal value (int) of the array
public int getVal(){
	int temp = 0;
	for(int i = 0;i<8;i++){
		if(bytes[i] == true){
			temp = temp + (int) java.lang.Math.pow(2,i);
		}
	}
	return temp;
}

}