| Author |
Why can't I sum two byte variables ?
|
Latif Ben
Greenhorn
Joined: Jun 23, 2011
Posts: 5
|
|
|
|
 |
Zeeshan Sheikh
Ranch Hand
Joined: Nov 20, 2011
Posts: 143
|
|
|
Binary operation (+) in java would return integer which is why there is loss of precision. You have to explicitly cast expression back to byte.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5886
|
|
Also, to keep your code readable, declare only one variable per line:
Also, don't increase your indent level unless you increase your block depth
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5886
|
|
Zeeshan Sheikh wrote:Binary operation (+) in java would return integer which is why there is loss of precision. You have to explicitly cast expression back to byte.
Note, however, that the += operator does the cast for you, so
should work.
|
 |
 |
|
|
subject: Why can't I sum two byte variables ?
|
|
|