Here you can find the source of bin2hex(String str)
public static String bin2hex(String str)
//package com.java2s; //License from project: Apache License public class Main { public static String bin2hex(String str) { String s = dec2hex(Integer.parseInt(str, 2)); return s; }//from ww w . jav a 2s. c o m public static String dec2hex(int dec) { String s = ""; s = Integer.toHexString(dec).toUpperCase(); if (s.length() % 2 != 0) { s = padleft(s, s.length() + 1, '0'); } return s; } public static String padleft(String oristr, int len, char alexin) { int strlen = oristr.length(); String str = ""; if (strlen < len) { for (int i = 0; i < len - strlen; i++) { str = str + alexin; } } str = str + oristr; return str; } }