String to Hex

What is Hexadecimal?

Hexadecimal is a numeral system that uses 16 symbols (0-9 and A-F/a-f) to represent values. Widely used in computer systems for memory addressing, color codes, and low-level data representation.

What is a String?

A string is a sequence of characters that may contain letters, numbers, symbols, and other text data used to represent textual content.

String Encoding Methods

String encoding is the process of converting characters into binary data for storage or transmission. Common encodings include: ASCIIUTF-8GBK

Hexadecimal Advantages

Direct conversion with binary (1 hex digit = 4 bits)
More compact and readable than binary
Standard representation for memory addresses
Widely used in color codes (#RRGGBB) and network protocols

What is ASCII

American Standard Code for Information Interchange (ASCII) uses 7 bits to represent 128 characters including English letters, numbers, and control characters. Extended ASCII uses 8 bits (0-255).

What is UTF-8

Unicode's variable-length character encoding: 1 to 4 bytes, fully compatible with ASCII。

Java String to Hex Implementation

      
public static String stringToHex(String input) {
    StringBuilder sb = new StringBuilder();
    for (char c : input.toCharArray()) {
        sb.append(Integer.toHexString((int)c));
    }
    return sb.toString();
}
      
      

Python String to Hex Implementation

      
def string_to_hex(s):
    return s.encode('utf-8').hex()

print(string_to_hex("Hello"))  #:48656c6c6f