java - Convert Byte[] to int -
i have method converts signed or non-signed byte
int
, doesn't return supposed return. can point out issue in 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 wav file in order calculate snr. returned value conversion should give beetween 0 , 255. application should compare 2 waves file, on orignal 1 , other modified , calculate snr .
are writing code exercise, or looking way it? if latter, suggest using bytebuffer. has getint method should trick.
Comments
Post a Comment