Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Adella Garcia   on Feb 07 In Java Category.

  
Question Answered By: Helene Stewart   on Feb 07

A "byte" variable in Java can store numbers of 8 bits,
if you add two bytes you can obtain a number of 9 bits.
As you can see, a "byte" can not store that number.

I didn't see the program you are doing, but in general,
a simple solution is to use a "short" (16 bits) to store
the addition.

But, there are some special cases (on compression
algorithms as an example) where you can substract 256
if the addition is greater than 256, and take a
similar decision on the decompression process, but
like I said, that will depend on what your algorithm
does.

Share: