Java Binary to Hex binToHex(String sBinString)

Here you can find the source of binToHex(String sBinString)

Description

bin To Hex

License

Open Source License

Declaration

public static String binToHex(String sBinString) 

Method Source Code

//package com.java2s;

public class Main {
    public static String binToHex(String sBinString) {
        String sHexString = "";
        String sTemp = "";

        while (sBinString.length() >= 4) {

            sTemp = sBinString.substring(0, 4);
            sBinString = sBinString.substring(4, sBinString.length());
            sHexString += Integer.toHexString(Integer.parseInt(sTemp, 2));
        }/*from  w w w  .j  a v a 2 s  .c  om*/

        if (sBinString.length() > 1) {
            for (int i = 0; i < 4 - sBinString.length(); i++) {
                sBinString = "0" + sBinString;
            }
            sHexString += Integer.toHexString(Integer.parseInt(sBinString,
                    2));
        }

        return sHexString;
    }
}

Related

  1. binaryToHexString(String binaryValue)
  2. binToHex(byte[] bin)
  3. binToHex(byte[] bytes)
  4. binToHex(byte[] data)
  5. binToHex(String bin)
  6. binToHexString(byte[] bytes)