Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * 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;
    }
}