Android Long to Hex Convert getBinaryString(long src)

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

Description

7 => 00000111

License

Open Source License

Parameter

Parameter Description
src a parameter

Declaration

public static String getBinaryString(long src) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*ww  w.  j a  v a  2  s .  com*/
     * 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;
    }
}