Java Utililty Methods ASCII to Hex

List of utility methods to do ASCII to Hex

Description

The list of methods to do ASCII to Hex are organized into topic(s).

Method

byte[]ascii2Hex(byte[] in)
ascii Hex
byte[] temp1 = new byte[1];
byte[] temp2 = new byte[1];
int i = 0;
byte[] out = new byte[in.length / 2];
for (int j = 0; i < in.length; j++) {
    temp1[0] = in[i];
    temp2[0] = in[(i + 1)];
    if ((temp1[0] >= 48) && (temp1[0] <= 57)) {
...
voidAscii2Hex(int len, byte data_in[], byte data_out[])
Ascii Hex
byte temp1[] = new byte[1];
byte temp2[] = new byte[1];
for (int i = 0, j = 0; i < len; j++) {
    temp1[0] = data_in[i];
    temp2[0] = data_in[i + 1];
    if (temp1[0] >= '0' && temp1[0] <= '9') {
        temp1[0] -= '0';
        temp1[0] = (byte) (temp1[0] << 4);
...
byte[]asciiToHex(byte[] src, int len, int padding)
ascii To Hex
byte[] bcd = new byte[len];
byte[] asc = null;
if (padding == 0) {
    asc = lpBytes(src, len * 2, (byte) 0x30);
} else {
    asc = rpBytes(src, len * 2, (byte) 0x30);
for (int i = 0; i < len; i++) {
...
StringASCIIToHex(int args, int len)
ASCII To Hex
String str = Integer.toHexString(args);
if (str.length() < len) {
    while (str.length() < len) {
        if (str.length() == len) {
            return str;
        str = "0" + str;
return str.toUpperCase();
StringasciiToHex(String ascii)
ascii To Hex
if (ascii == null)
    throw new NullPointerException();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ascii.length(); i++) {
    int asciiCode = ascii.charAt(i) & 0xFF;
    sb.append(String.format("%02x", asciiCode));
return sb.toString();
...
StringasciiToHex(String ascii)
Converts an ascii string into a string containing its hex value.
StringBuffer hex = new StringBuffer();
if (ascii == null) {
    return null;
for (int i = 0; i < ascii.length(); i++) {
    char aChar = ascii.charAt(i);
    int ndx = (aChar >> 4) & 0x000f;
    hex.append(hexChars[ndx]);
...
StringasciiToHex(String ascii)
convert ascii String into hexa String
StringBuilder hex = new StringBuilder();
for (int i = 0; i < ascii.length(); i++) {
    hex.append(Integer.toHexString(ascii.charAt(i)));
return hex.toString();
StringasciiToHex(String asciiValue)
ascii To Hex
char[] chars = asciiValue.toCharArray();
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
    hex.append(Integer.toHexString(chars[i]));
return hex.toString();
StringasciiToHexStr(String src)
ascii To Hex Str
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < src.length(); i++)
    sBuilder.append(String.format("%02X", Integer.valueOf(src.charAt(i))));
return sBuilder.toString();