Search: | |||||

| ||||

Home » Forum » Java | RSS Feeds |

I need your help please.

I'm programming something about bytes.

x[i] = x[i]+y[i];

x and y are byte arrays.

When I add two bytes, it says that it is possible to lose precision.

In my program, i don't care about the precision being lost!

How can I overcome this problem?

I'm looking forward to hearing from you as soon as possible.

x[i] =new Integer(x[i]+y[i]).byteValue(); will work

When 2 bytes are added, the addition returns an int. Just cast the

addition back to a byte.

x[i] = (byte)(x[i]+y[i]);

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.

Didn't find what you were looking for?
Find more on S.O.S! HELP!
Or get search suggestion and latest updates.

Related Topics:

- Help on a designing the help Screen
- pleass i want 2 help this Question.....so plz help me.....
- need help urgently
- LEARNER NEED HELP
- Help needed
- Help Me to Recover VBA Password
- Is there anyone to help me for problem given below
- Can anyone help me
- I need help in assembly x86,Irvine
- pleaaaaaaaase any help
- linked list help
- Please , Help Cant Solve This Pattern ...
- Need urgent help !
- Can any one help me with VBA Code?
- Node help
- Help...Shell script
- HELP - GUI Multi-Threading Client/Server Chat Program Thread Problem
- I have a problem in Shell script Help me Guys please :)
- help me with finding shortest path
- Please help with MSP430 program.
- Need help with my source code.
- Need help for C++
- help with errors
- can i get help
- help me please