大家好,我的需求是给一个任意长度的字符串,要求通过一个哈希算法最后特到的是一个64位长度的二进制字符串。
我举个例子 比如字符串是“阿萨德撒啊打扫撒” 通过算法特到的是“01011010010110100101101001011010”这个二进制长度为64位的。(算似与MD5,但是返回值是64为的二进制)。多谢!!!大家!!
分不够我可以加!!! 急!!
我举个例子 比如字符串是“阿萨德撒啊打扫撒” 通过算法特到的是“01011010010110100101101001011010”这个二进制长度为64位的。(算似与MD5,但是返回值是64为的二进制)。多谢!!!大家!!
分不够我可以加!!! 急!!
public static String toFullBinaryString(int num) {
char[] chs = new char[Integer.SIZE];
for(int i = 0; i < Integer.SIZE; i++) {
chs[Integer.SIZE - 1 - i] = (char)(((num >> i) & 1) + '0');
}
return new String(chs);
}
public static void bitString(String str){
int hashcode = str.hashCode();
String strOfHashcode = toFullBinaryString(hashcode);
String symmStr = new StringBuffer(strOfHashcode).reverse().toString();
String output = strOfHashcode + symmStr;
System.out.println(output);
}
public static void main(String args[]){
String[] strArray = {"阿萨德撒啊打扫撒", "中华人名共和国 ", "鬼子"};
for(int i=0; i<strArray.length; i++)
bitString(strArray[i]);
}
}
输出:
1000000101011111101110001101010000101011000111011111101010000001
1011111110111101101010000101001001001010000101011011110111111101
0000000000010011001001111001010000101001111001001100100000000000
System.out.println(Long.toBinaryString((long)"阿萨德撒啊打扫撒".hashCode()));
欢迎加入 2987841 java交流群 共同交流java,面试 心得