Re: why does adding 2 bytes together result in an int?




moondaddy wrote:
my understanding is that the max value of a byte is 255. Therefore, why
does the following code get a compile error?

byte val1 = 10;
byte val2 = 23;
byte ttl;
ttl = val1 + val2; //this line wont compile

compile error: Cannot implicitly convert type 'int' to 'byte'.

val1 + val2 = 33 which is still in the range of a byte. therefore, why do I
need to convert ttl into an int?

What's 128 + 128 ?

--
Larry Lard
Replies to group please

.



Relevant Pages


Loading