cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert ASCII to Hexa decimal

sahithi_moparthi
Contributor
0 Kudos

Hi Every One,

     Could anyone suggest me how to convert the ASCII to Hexadecimal (using UDF /Java mapping).

Thanks in Advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

Ryan-Crosby
Active Contributor
0 Kudos

Hi Sahithi,

Here is a sample of a java mapping I have done where I had to take the input stream and convert it to a hexadecimal string so it could be processed in a proxy:

private String digits = "0123456789ABCDEF";

// Initialize variables, objects for processing

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

int c, len;

byte[] bytes = new byte[4096];

StringBuffer sb = new StringBuffer();

// Convert input stream to string in hexadecimal notation

try {

  while((len = in.read(bytes)) != -1)

  {

    for(int i = 0; i < len; i++)

    {

      c = bytes[i] & 0xff;

      sb.append(digits.charAt(c >> 4));

      sb.append(digits.charAt(c & 0xf));

    }

  }

}catch (IOException e) {

    e.printStackTrace();

}

// Now write to output stream

try {

  // Output file data in hexadecimal string

  bw.write(sb.toString());

  bw.close();

}catch (IOException ex) {

  ex.printStackTrace();

}

I tried using the Java version of toHexString() but found that there was some kind of bug that resulted in a bad string output.

Regards,

Ryan Crosby

rajasekhar_reddy14
Active Contributor
0 Kudos