I just realised that bitSet() only works for bits 0 to 31. When wanting to set bits higher than 31, I seem to have to use bitWrite(); Is this an error or a wanted behaviour?
Regards,
Dani
uint64_t sternbilder = 0;
bitSet(sternbilder, 8); // for bits from 0 to 31
bitWrite(sternbilder, 32, 1); // for bits 32 and above
Are you sure about your observations?
The code for bitSet is a macro which looks long compatible to me.
Also bitWrite is a macro using bitSet.
So if bitWrite works for longs; bitSet should as well
A solution for 64bit values is to define the following macros, as they use explicit an unsigned long long as datatype.
(you include these in the Arduino.h )
Rob
The existing macros should work for unsigned long, right?
That is from bit 16 to 31
Your proposal is needed for bits 32 to 63
Or did I miss something?
Best regards
Jantje
Rob, you are so fast I'm hardly able to type in your suggestions before you have an even better one I patched the Print.h und Print.cpp and included your #definitions for 64bit magic an am very happy that now everything works as expected. Thank you very much - you should add this code to future arduino-IDE-releases!
Jantje, I think you are right - I think I have gotten the 15 wrong - it seems to be 31 that is the limit with the normal bitSet()-function. Please excuse my misswriting. Dani.
C++ allows us to do things beyond macros. How about a template class for any size bitset? With operator syntax and that is adapted for an 8-bit machine as ATmega328.
enum {
GREEN,
BLUE,
YELLOW,
RED
};
int main()
{
bitset_t<48> b;
TRACE(b[GREEN]);
b += GREEN;
TRACE(b[GREEN]);
b -= GREEN;
TRACE(b[GREEN]);
b += RED;
b.dump();
b += YELLOW;
b.dump();
b += 47;
b.dump();
b += 48;
b.dump();
b += 100;
b.dump();
return (0);
}