BinaryUtil

/**
 * 功能:获取int和long型数据的二进制字符串
 * 作者:邵江
 * 时间:2011.7.26
 */
public class BinaryUtil {

	/**
	 * 获取一个int型数据的二进制字符串
	 * @param i
	 * @return
	 */
	public static String getIntBinaryString(int i){
		String binaryString = null;
		binaryString = Integer.toBinaryString(i);
		if(binaryString.length()<32){
			int complementLength = 32 - binaryString.length();
			String complement = "";
			for(int n = 0;n<complementLength;n++){
				complement+="0";
			}
			binaryString=complement+binaryString;
		}
		return binaryString;
	}
	
	/**
	 * 获取一个long型数据的二进制字符串
	 * @param l
	 * @return
	 */
	public static String getLongBinaryString(long l){
		String binaryString = null;
		binaryString = Long.toBinaryString(l);
		if(binaryString.length()<64){
			int complementLength = 64 - binaryString.length();
			String complement = "";
			for(int n = 0;n<complementLength;n++){
				complement+="0";
			}
			binaryString=complement+binaryString;
		}
		return binaryString;
	}
}

你可能感兴趣的:(String,Class)