giải mã ký tự có dấu

giải mã ký tự có dấu
mail@pastecode.io avatar
unknown
java
3 years ago
1.2 kB
2
Indexable
Never
    //-------------------------- chuyen doi 1 chuoi ky tu sang chuoi binary theo unicode -----------------------//
	private String textToBinary(String str) {
    	String s = "";
    	for(int i = 0; i < str.length(); i++) {
    		s = s + charToBinary(str.charAt(i));
    	}
    	return s;
    }
    
    //--------------------------  chuyen doi 1 chuoi binary sang so nguyen lon -----------------------//
	private BigInteger binaryToDecimal(String binaryString) {
    	return new BigInteger(binaryString, 2);
    }
    
    //-------------------------- chuyen doi 1 so nguyen lon sang 1 chuoi binary ----------------------//
	private String decimalToBinary(BigInteger bigInt) {
    	String s = bigInt.toString(2);
    	while(s.length() % 16 != 0) {
    		s = '0' + s;
    	}
    	return s;
    }
    
    //-------------------------- chuyen 1 chuoi binary ve lai chuoi unicode ----------------------//
	private String binaryToText(String binString) {
        String text = "";
        for (int i = 0; i < binString.length() / 16; i++) {
            int a = Integer.parseInt(binString.substring(16 * i, (i + 1) * 16), 2);
            text += (char)(a);
        }
        return text;
    }