Can I convert a 32 bit boolean array to a long?

Hi,
I am writing a keyboard scanner, with a shift register providing the rows, and an Arduino the columns on an 8*8 scan matrix.

I am storing whether the key is pressed or not in a Boolean array [64]

That way I can use a simple for loop to control the scan.

The last state is kept in another Boolean array.

But I need to detect whether a key has changed state.

I could use another for loop - but am looking at a simple / quick way to check if there is a change..

Can I cast the array into a long and use a simple check to see if the two arrays are the same?

I have tried to google this - but found some very confusing items!

Many thanks
Andy

A normal 'unsigned long' on a Arduino Uno is 32 bit. You need two of them to store 64 bits.
You need another two to store the previous state (or last state).

bitSet() and bitWrite() could be used.
https://www.arduino.cc/en/Reference/BitSet
https://www.arduino.cc/en/Reference/BitWrite
https://www.arduino.cc/en/Reference/BitRead

When you are using the Due, the uint64_t can perhaps be used.

Or use a structure of 8 bytes with 64 bit fields.
I don't know if an array of 64 bit fields (and each element being just one bit) is possible. I have never tried that.
To compare the structure and to copy it to an other structure is possible with memcmp en memcpy.

I don't know which option is the best. It depends on your code and how you want to use the bits.
Do you have a few examples of other keyboard scanners ?

I wonder could you store the two 8 x 8 scans in 2 bytes and use them to figure out the keys

...R

you can struct two uint32_t's like this:

struct sixtyfourBits{
  uint32_t hiBits;
  uint32_t lowBits;
};

sixtyfourBits myKeyboard = {0b00011110000011010010010111110111, 0b00011110000011010010010111110111};
sixtyfourBits lastReading = {0b00011110000011010010010111110111, 0b00011110000011010010010111110111};

void setup()
{
  Serial.begin(9600);
  Serial.println(doTheyMatch()? "matched" : "different");
}


void loop() {


}

bool doTheyMatch()
{
  return (myKeyboard.hiBits == lastReading.hiBits && myKeyboard.lowBits == lastReading.lowBits);
}
[code]

Thanks guys for the suggestions....

Koepel - I like your suggestion of using BitSet - etc.
I hadn't some across those before - and could be ideal.
Might be an alternative to using a mask to set the scan columns.

Koepel:
Do you have a few examples of other keyboard scanners ?

I have found one good example on the web - but it was for 32 keys, and I didn't like the way the code had been written. we all have our own ideals I suppose!

Ideally I will need an 8*12 matrix - to cover switches s well, so quite a lot of 'bits' to manipulate.

Andy

Note the UNO also support int64_t and uint64_t