Hello, i am working with a couple of 10x10 matrix, one matrix recieves the 10 digit BINARY number and the other one displays the input. My previous prototype was working on a 8x8 matrix so the byte data type fits perfect to me for the input, indeed my data input variables were declared as follows:
byte inputState [size] = { B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000 };
I was able to read data using bitRead:
void readBitState(){
bool currentState [] = { 0,0,0,0,0,0,0,0 };
for(int i = 0; i < sizeof(inputState); i++){
Serial.print((String)"State at " + i + " : ");
for(int j = 0; j < sizeof(inputState); j++){
currentState[i] = bitRead(inputState[i],j);
Serial.print((String)state[i]);
}
Serial.println(" ");
}
}
Now i need to use not 8 but 10 digits per row, since my input is Binary i understand that each of my new input (row) requires 2 bytes, Since i prefer not to use the long data type that uses 4 bytes of memory i need to know how it is possible to use the B00000000 byte format similarly but for the INT data type?
Thanks in advance.
Yes. You can initialize any variable using any of several human readable text representations for numbers, including the 0Bxxx format.
Thanks, i read the documentation and now understand the mistake was passing the data formated as:
B0000000000
instead of:
0B0000000000
So in summary i was ignoring the 0 before the B, now i am able to compile and run my code well. Thank you !
The "Bxxx" format is a bunch of names defined by the Arduino core library. It only goes up to 8 bits and makes it hell for anyone wanting to use the names B0, B1, B00, B01, B10, B11...
The 0Bxxxx (or 0bxxxx) is a compiler thing and works for any reasonable length. At least 64 bits (I just checked):
uint64_t binary = 0b0000000000000000000000000000000000000000000000000000000000000000;
Thanks for the information sir, Dealing with bytes at this level is not common where i come from, however, now i know how to use the 0bxxx format but at the same take into consideration the boundaries.
Dealing with bytes and 0b or B prefixes isn't common anywhere - most of us use hex.
TheMemberFormerlyKnownAsAWOL:
Dealing with bytes and 0b or B prefixes isn't common anywhere - most of us use hex.
Historical note for young programmers:
Back before a 'byte' became standardized at 8 bits and hexadecimal became standard for representing blocks of bits, many programmers used octal. Even to this day, the C and C++ programming languages treat an integer constant as octal if it starts with a zero.
If you try to 'neaten' your columns by left padding with zeroes you will have problems.
int values[] = {
0000, 0025, 0050, 0075, // In decimal these are: 0, 21, 40, 61
0100, 0125, 0150, 0175, // In decimal these are: 64, 85, 104, 125
0200, 0225, 0250, 0275, // In decimal these are: 128, 149, 168, 189
0300, 0325, 0350 // In decimal these are: 192, 213, 232
};
These are interpreted as octal. IF you are lucky you will use the digits 8 or 9 and get an "invalid digit in octal constant" error.