aspose file tools*
The moose likes Beginning Java and the fly likes Why can't I sum two byte variables ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why can Watch "Why can New topic
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: 144

Binary operation (+) in java would return integer which is why there is loss of precision. You have to explicitly cast expression back to byte.


MySQL Blog
http://mysqlearner.blogspot.com/
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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: 6109
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why can't I sum two byte variables ?
 
Similar Threads
byte... x
Question (implicit conversion)
how to compare the values in arrays
Play video file frame by frame
Rules Roundup #108