Java XML Hex stringToHex(String str)

Here you can find the source of stringToHex(String str)

Description

Converts a String to hexadecimal.

License

Open Source License

Parameter

Parameter Description
str The String to convert.

Return

A String containing a hexadecimal equivalent of the given lexical argument.

Declaration

public static String stringToHex(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**/*from w  ww .  ja  v  a 2  s . c o  m*/
     * Converts a {@code String} to hexadecimal.
     * 
     * @param str The {@code String} to convert.
     * @return A {@code String} containing a hexadecimal equivalent of the given
     *         lexical argument.
     */
    public static String stringToHex(String str) {
        byte bytes[] = str.getBytes();
        return DatatypeConverter.printHexBinary(bytes);
    }
}

Related

  1. printHexBinary(final byte[] deviceMessage)
  2. readHexString(ByteBuffer buf)
  3. sha1Hex(final String text)
  4. sha1Hex(String data)
  5. sha1Hex(String message)
  6. toByteArray(String hex)
  7. toByteArray(String hexDumpString)
  8. toByteArrayFromHexString(String s)
  9. toByteFromHexString(String hexString)