I have this method that converts a signed or non-signed byte
to int
, but it doesn't return what it is supposed to return. Can someone point out the issue in the below code?
public int convertByteToInt(byte[] b){
int value= 0;
for(int i=0;i<b.length;i++){
int n=(b[i]<0?(int)b[i]+256:(int)b[i])<<(8*i);
value+=n;
}
return value;
}
Edited :
I'am actualy reading a wav file in order to calculate the SNR. the returned value from the conversion should give something beetween 0 and 255. The application should compare 2 waves file, on is the orignal one and the other is modified and calculate the SNR .