_Kurimatzu_ Postado Agosto 16, 2016 Denunciar Postado Agosto 16, 2016 (editado) private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); private static HexStringConverter hexStringConverter = null; public HexStringConverter() { } public static HexStringConverter getHexStringConverterInstance() { if (hexStringConverter == null) { hexStringConverter = new HexStringConverter(); } return hexStringConverter; } public String stringToHex(String input) throws UnsupportedEncodingException { if (input == null) { throw new NullPointerException(); } return asHex(input.getBytes()); } public String hexToString(String txtInHex) { byte[] txtInByte = new byte[txtInHex.length() / 2]; int j = 0; for (int i = 0; i < txtInHex.length(); i += 2) { txtInByte[j++] = Byte.parseByte(txtInHex.substring(i, i + 2), 16); } return new String(txtInByte); } private String asHex(byte[] buf) { char[] chars = new char[2 * buf.length]; for (int i = 0; i < buf.length; ++i) { chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4]; chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F]; } return new String(chars); } Estou usando esse método para gerar um valor hexadecimal. Quero gerar um valor nulo (00). É possível? (bem, eu tentei usar o ".", porém ao editar no 010 editor, não é 00 e sim 2E). Editado Agosto 16, 2016 por _Kurimatzu_
Lüigi! Postado Agosto 16, 2016 Denunciar Postado Agosto 16, 2016 Não entendi muito bem, você quer gerar um hexa nulo? 1
_Kurimatzu_ Postado Agosto 16, 2016 Autor Denunciar Postado Agosto 16, 2016 Não entendi muito bem, você quer gerar um hexa nulo? Sim.
Lüigi! Postado Agosto 16, 2016 Denunciar Postado Agosto 16, 2016 Sim. Acho que uma gambiarra para isso, seria você identificar se a String é vazia (isEmpty()) e "manualmente" retornar o 00
_Kurimatzu_ Postado Agosto 16, 2016 Autor Denunciar Postado Agosto 16, 2016 (editado) Acho que uma gambiarra para isso, seria você identificar se a String é vazia (isEmpty()) e "manualmente" retornar o 00 Problema Resolvido. Editado Agosto 16, 2016 por _Kurimatzu_
jetta Postado Agosto 16, 2016 Denunciar Postado Agosto 16, 2016 Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas. Atenciosamente, Gamer's Board
Pergunta
_Kurimatzu_
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); private static HexStringConverter hexStringConverter = null; public HexStringConverter() { } public static HexStringConverter getHexStringConverterInstance() { if (hexStringConverter == null) { hexStringConverter = new HexStringConverter(); } return hexStringConverter; } public String stringToHex(String input) throws UnsupportedEncodingException { if (input == null) { throw new NullPointerException(); } return asHex(input.getBytes()); } public String hexToString(String txtInHex) { byte[] txtInByte = new byte[txtInHex.length() / 2]; int j = 0; for (int i = 0; i < txtInHex.length(); i += 2) { txtInByte[j++] = Byte.parseByte(txtInHex.substring(i, i + 2), 16); } return new String(txtInByte); } private String asHex(byte[] buf) { char[] chars = new char[2 * buf.length]; for (int i = 0; i < buf.length; ++i) { chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4]; chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F]; } return new String(chars); }Estou usando esse método para gerar um valor hexadecimal.
Quero gerar um valor nulo (00).
É possível? (bem, eu tentei usar o ".", porém ao editar no 010 editor, não é 00 e sim 2E).
Editado por _Kurimatzu_5 respostass a esta questão
Posts Recomendados