How to add the 256 value only to negative numbers?Result i get from modorg is the same as modulus [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question//arrays modulus and modrog
byte[] modulus ={-30, 0 , 25, 70,-25,-3,-2};
byte[] modorg=new byte[7];
//the loop that counts the elements
for (int j = 0; j < modulus.length; j++)
{
if (modulus[j] < 0)
{
modorg[j] = (byte) ((int)modulus[j] + 256);
}
else
{
modorg[j]=modorg[j];
}
}
Adding 256 to a byte is like adding 360 to a degree :) You will get the same value. You probably want to add 128?
精彩评论