Fixed some bugs in byte util

This commit is contained in:
Ziver Koc 2016-05-13 17:03:11 +02:00
parent 28d1f04246
commit 50ea517cf3
4 changed files with 9 additions and 7 deletions

View file

@ -144,7 +144,7 @@ public class ByteUtil {
byte rest = 0;
for (int i=0; i<data.length; ++i){
rest = (byte)(getBits(data[i], shiftBy-1, shiftBy) << 8 - shiftBy);
data[i] >>>= shiftBy;
data[i] = (byte)((int)(data[i]&0xFF) >> shiftBy);
if(i != 0)
data[i-1] |= rest;
}

View file

@ -101,11 +101,11 @@ public class Converter {
if(hex.startsWith("0x"))
hex = hex.substring(2);
byte[] b = new byte[(int)Math.ceil(hex.length()/2.0)];
for(int i=hex.length()-1; i>=0; i-=2){
if(i-1 < 0)
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i));
for(int i=0; i<hex.length(); i+=2){
if(i+1 >= hex.length())
b[(i+1)/2] = hexToByte(hex.charAt(i), '0');
else
b[(hex.length()-i-1)/2] = hexToByte(hex.charAt(i-1), hex.charAt(i));
b[(i+1)/2] = hexToByte(hex.charAt(i), hex.charAt(i+1));
}
return b;
}