rodrigo_rosalin
Legal, estava dando uma procurada aqui em manipulação de bits, não sabia que dava pra deslocar mais de um bit de uma vez, muito obrigado!
vou postar a classe que fiz pra trabalhar com byte sem sinal.
/**
*
* @author rodrigo.rosalin
*/
public class ByteBufferWork
{
public static short getUnsignedByte(byte b)
{
return ((short) (b & 0xFF));
}
//Converte os elementos de um vetor de byte para um vetor do tipo short com os valores corretos
public static short[] getUnsignedBytes(byte[] b, int tam)
{
short aux[] = new short[tam];
for(int i=0;i<b.length;i++)
{
if (b[i] < 0)
aux[i] = (short)(b[i] & 0xFF);
else
aux[i] = b[i];
}
return aux;
}
public static byte putUnsignedByte(int value)
{
if (value > 127)
return (byte)(value & 0xFF);
else
return ((byte)value);
}
public static byte[] putUnsignedBytes(int[] values, int tam)
{
byte aux[] = new byte[tam];
for(int i=0; i<values.length; i++)
aux[i] = (byte)(values[i] & 0xFF);
return aux;
}
}