Ir para conteúdo
  • 0

[Resolvido] Hexadecimal


_Kurimatzu_

Pergunta

 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_
Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...