Addition or Subtraction to Byte

I am trying to add or subtract 1 from a byte variable. I can confirm that the value i am using will exactly range between 0 to 15 so I am using byte. But when i was testing out the code in java i had to explicitly convert like

byte a=7;
a=(byte)(a-1);

But do i have to do it in arduino too? Altought doing that doesnt show any error, I am concerned it might cause a run time error. Any help would be appreciated.

no, you don't need a type-casting in this case.

You might like

a--;

In Java, the byte type is signed, unlike Arduino.

Oh yeah, i totally forgot that existed

Thanks everyone, so i guess the final answer is no type casting required

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.