Here you can find the source of Ascii2Hex(int len, byte data_in[], byte data_out[])
public static void Ascii2Hex(int len, byte data_in[], byte data_out[])
//package com.java2s; //License from project: Apache License public class Main { public static void Ascii2Hex(int len, byte data_in[], byte data_out[]) { byte temp1[] = new byte[1]; byte temp2[] = new byte[1]; for (int i = 0, j = 0; i < len; j++) { temp1[0] = data_in[i];/*from ww w .j a v a 2s . c o m*/ temp2[0] = data_in[i + 1]; if (temp1[0] >= '0' && temp1[0] <= '9') { temp1[0] -= '0'; temp1[0] = (byte) (temp1[0] << 4); temp1[0] = (byte) (temp1[0] & 0xf0); } else if (temp1[0] >= 'a' && temp1[0] <= 'f') { temp1[0] -= 0x57; temp1[0] = (byte) (temp1[0] << 4); temp1[0] = (byte) (temp1[0] & 0xf0); } if (temp2[0] >= '0' && temp2[0] <= '9') { temp2[0] -= '0'; temp2[0] = (byte) (temp2[0] & 0x0f); } else if (temp2[0] >= 'a' && temp2[0] <= 'f') { temp2[0] -= 0x57; temp2[0] = (byte) (temp2[0] & 0x0f); } data_out[j] = (byte) (temp1[0] | temp2[0]); i += 2; } } }