Conversão de array de bytes para int

1 resposta
M

oii,

preciso converter um inteiro(o maior deles, no caso), para um array de bytes, e depois isso preciso recuperar o valor inteiro deste array, estou conseguindo fazer isso, mas quando o numero informado eh um inteiro[telefone removido]), ele não me retorna exatamente este numero e sim 255, como faço para conseguir exatamente o numero informado = [telefone removido] ?

int uu = [telefone removido];/
			
ByteArrayOutputStream byOutInteger = new ByteArrayOutputStream();
byOutInteger.write(uu);

byte[] cadeiaInteger = byOutInteger.toByteArray();
					

ByteArrayInputStream byInput = new ByteArrayInputStream(cadeiaInteger);					
int obj = byInput.read();

obrigada,
Marci

1 Resposta

I

Tenta isto:

final int uu = [telefone removido];
final String value = String.valueOf(uu);
final byte[] valueBytes = value.getBytes();

//transfere com o ByteArrayOutputStream... implemente-o
writeOutput(valueBytes);

//Do outro lado com o ByteArrayInputStream... implemente-o
String recovered = readInput(bais);
final int uu2 = Integer.parseInt(recovered);

T+

Criado 26 de novembro de 2006
Ultima resposta 28 de nov. de 2006
Respostas 1
Participantes 2