Finally relized how helpful bitwise opperations are, but I'm still having a hard time understanding the syntax "a bit".
I'm trying to prove out a shift opperation for my braille keyer so I can shift letters to numbers as done in braille. Going to use the 8th button to do the shifting, thus fliping the most significant bit. I'm trying to do a comparison that would exclude that bit to read some of the same values from my existing conversion array (a,b,c,d,e,f,g,h,i,j,) as numbers (1,2,3,4,5,6,7,8,9,0,)
Now there may be a better way to achieve what I'm doing all together, (im open to suggestions) but mainly I'm currious how to exclude the 8th bit once I have determined it is 1? In this way only the other buttons will be compared against the array.
Here is where I'm at so far. Please ignore the convert argument was using this function to convert both ways.
#define ENCODEAMT 32 // size is defined to structure iteration amount
byte byteToBraille [3][ENCODEAMT] // brialle convertion array
{
{ // input in characters
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 8, ' ', '-',';','.', '?', }
,
{ //corrisponding braille binary output in decimal form, read from least significant bit
1 , 5 , 3 , 11, 9 , 7 , 15, 13, 6 , 14, 17, 21, 19, 27, 25, 23, 31, 29, 22, 30, 49, 53, 46, 51, 59, 57 ,64, 32, 48, 40, 34, 43, }
};//each bit in the corrisponding bytes represents a "bump" state
void setup()
{
Serial.begin(9600);
for(byte i=0;i<255;i++)
{
Serial.print(i);
Serial.print(" - ");
Serial.write(brailleConvert(i, 0));
Serial.println();
}
}
void loop()
{
}
byte brailleConvert(byte letter, boolean convert)
{//if conversion is desired set true, set false for "if braille" return letter opperation
if(letter & (1<<7))
{//if most significant bit is flaged "shift is pressed"
for(byte i=0; i<10; i++)
{
if(letter ~ (1<<7) == (byteToBraille[!convert][i]))
{// for a matching letter in the array
return (byteToBraille[convert][i]-48);
}// return the corrisponding translation
}
if(letter ~ (1<<7) == (byteToBraille[!convert][10]))
{
return 48;//'0'
}
}
else
{
for(byte i=0; i<ENCODEAMT;i++)
{
if(letter == (byteToBraille[!convert][i]))
{// for a matching letter in the array
return (byteToBraille[convert][i]);
}// return the corrisponding translation
}
}
return 0;
}
Currently the tilde mucks this up, was under the notition that appying "not" to the particular bit would work, but this syntax is definately wrong.