Android Byte to Hex Convert getBinaryString(byte src)

Here you can find the source of getBinaryString(byte src)

Description

7 => 00000111

License

Open Source License

Parameter

Parameter Description
src a parameter

Declaration

public static String getBinaryString(byte src) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w w  .j  a  v  a2 s.  c  o  m*/
     * 7 => 00000111
     * 
     * @param src
     * @return
     */
    public static String getBinaryString(long src) {

        String binaryString = Long.toBinaryString(src);
        String temp = "";
        for (int i = 0; i < Long.SIZE - binaryString.length(); i++) {
            temp += "0";
        }
        binaryString = temp + binaryString;
        return binaryString;
    }

    /**
     * 7 => 00000111
     * 
     * @param src
     * @return
     */
    public static String getBinaryString(byte src) {
        String binaryString = Integer.toBinaryString(src);
        if (binaryString.length() > Byte.SIZE) {
            binaryString = binaryString.substring(binaryString.length()
                    - Byte.SIZE);
        } else {
            String temp = "";
            for (int i = 0; i < Byte.SIZE - binaryString.length(); i++) {
                temp += "0";
            }
            binaryString = temp + binaryString;
        }
        return binaryString;
    }
}

Related

  1. byteToHexString(byte b)
  2. getHexString(byte i)
  3. toHexString(byte b)
  4. toHexString(byte byt)
  5. getBinaryStrFromByte(byte b)
  6. byteToHex(byte b)
  7. byteToHex(byte data)
  8. byteToHex(byte data)