Java Binary to Hex bin2hex(String str)

Here you can find the source of bin2hex(String str)

Description

binhex

License

Apache License

Declaration

public static String bin2hex(String str) 

Method Source Code

//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;
    }
}

Related

  1. bin2hex(final byte[] b)
  2. bin2hex(final byte[] base)
  3. bin2hex(int digit)
  4. bin2Hex(String bin)
  5. bin2hex(String bin)
  6. binaryString2hexString(String bString)
  7. binaryToHex(byte[] ba)
  8. binaryToHex(byte[] bytes)
  9. binaryToHex(byte[] data)