0x81 0x80

2 respostas
M
Novamente estou com um problema O código a seguir não tem função nenhum, só está ai para exemplificar o problema.
public static void main(String[] args) {
		String ida = "";
		String volta = "";
		String hex = "81800001000100030000";
		String wBuffer = "";
		for (int i = 0; i < hex.length(); i = i + 2)
			wBuffer = wBuffer
					+ (char) Integer.parseInt(hex.substring(i, i + 2), 16);
		byte[] sendData;
		sendData = wBuffer.getBytes();
		for (char ch : wBuffer.toCharArray())
			volta += Integer.toHexString(ch) + " ";
		System.out.print(volta + "\n");
		DatagramPacket sendPacket = new DatagramPacket(sendData,
				sendData.length);
		sendPacket.setData(sendData);
		String fa = new String(((byte[]) sendPacket.getData()));
		volta = "";
		for (char ch : fa.toCharArray())
			volta += Integer.toHexString(ch) + " ";
		System.out.print(volta);

	}
Quando executado ele retorna: [color=green] [/color] [color=red]81 80[/color][color=green] 0 1 0 1 0 3 0 0[/color] [color=darkred]3f 3f[/color][color=green] 0 1 0 1 0 3 0 0 [/color]

Quando o pacote chega do outro lado tanto o 80 quanto o 81 são transformados em 3f.
Alguém saberia como consertar isso.

2 Respostas

C

Eu não sei se tem como resolver, mas será que o problema não é o getBytes() que está tratando os valores como octal?

M

Ja resolvi.
Obrigado 8)

Criado 23 de maio de 2009
Ultima resposta 24 de mai. de 2009
Respostas 2
Participantes 2