Data types and arithmetic


So, I would like to send data from one arduino to another.
I set on using 12c and the wire library.
For that to work, i understand the datatypes sent / received need to be in bytes.

OK, so be it, seems reasonable request :slight_smile:
But for some reason (which is probably very basic) when I change my data types I get odd math.

byte hall1 = 5;
byte rev = 0;

void setup() {
ย  // put your setup code here, to run once:


void loop() {
ย  // put your main code here, to run repeatedly:
rev = (hall1*60);

For some reason, this sketch returns โ€œ44โ€ whereas running the same code with int data type returns 300. Which you would expect.

int hall1 = 5;
int rev = 0;

What is going on?

What is the largest number that will fit in a byte ? What is 5 * 60 ?

I foresee the use of unions in your project. One for sender, one for receiver.

Thank you guys, I will investigate :)

Perhaps this may help
I2C protocol is 8 bits - usually.
To take advantage of both I2C and ASCII protocol your โ€œdataโ€ should be represented as ASCII code AKA 7 bits.
For example numerical data โ€œ100โ€ should be converted to ASCII code and transferred as hex 31 30 30 AKA three ASCII characters 1 0 0.

Since you do not transfer binary representation of your data as 8 bits word you have means to detect and even correct errors caused by noisy transmission media.

Never mind the "limits of data type " - immaterial trivia in this case.