void setup(){
Serial.begin(9600);
delay(500);
}
unsigned char newByte(unsigned char a, unsigned char b){
/*
Return a byte whose:
- two most significant bits are the two least significant bits of "a"
- six least significant bits are the 6 least significant bits of "b"
*/
/*
The way I've done this sucks giant donkey balls because
I'm taking unsigned chars, which are only 8 bits,
converting them to arrays of integers, and then back
into unsigned chars. Integers require way more memory
and processing power to operate on. So this is wildly
inefficient and uses too many lines of code.
Also it just does not work and I am going to [redacted] hahahahahahhhahahahahhahahahahahahhahahahahahhahahahahahahaahahahahahahahahaaahahahahaaahahahahahaahaahahaahahahahaa
*/
int bits = 8;
//Make an array of integers out of the bits of input a.
int aByte[bits];
for(int i=bits;i>=0;i--){
aByte[i] = bitRead(a,i);
}
Serial.println("Value of input a:");
for(int i=0;i<bits;i++){
Serial.print(aByte[i]);
}
Serial.println();
//Make an array of integers out of the bits of input b.
int bByte[bits];
for(int i=bits; i>=0; i--){
bByte[i] = bitRead(b,i);
}
Serial.println("Value of input b:");
for(int i=0;i<bits;i++){
Serial.print(bByte[i]);
}
Serial.println();
//Make a new array out of the two inputs.
int c[bits] = {
aByte[0],aByte[1],bByte[0],bByte[1],
bByte[2],bByte[3],bByte[4],bByte[5]
};
Serial.println("New array contains: ");
for(int i=0;i<bits;i++){
Serial.print(c[i]);
Serial.print(",");
}
Serial.println();
//Create a byte out of the new aray
unsigned char result;
for(int i=0;i<bits;i++){
if (c[i] == 1){
bitWrite(result,i,1);
}
if (c[i] == 0){
bitWrite(result,i,0);
}
}
Serial.println("Value of new byte:");
for(int i=0;i<bits;i++){
Serial.print(bitRead(result,i));
}
Serial.println();
//Send that shit
return result;
}
bool checkAnswer(unsigned char givenAnswer, unsigned char correctAnswer){
if(givenAnswer == correctAnswer){
Serial.println("DING DING DING!");
return true;
}
else{
Serial.println("EXTREMELY LOUD INCORRECT BUZZER");
return false;
}
}
void loop(){
unsigned char a = 3; //00000011
unsigned char b = 63; //00111111
unsigned char solution = 255; //11111111
checkAnswer(newByte(a,b),solution);
delay(1000);
exit(0);
}