String表示的二进制数转换为BigInteger,BigInteger转换为Long类型二进制

String表示的二进制数转换为BigInteger,若二进制数以0开头,则转换为的BigInteger二进制数省掉第一个1前面的所有0。否则二进制形式和String表示时相同,原样输出,值未发生改变。
BigInteger转换为Long类型 -> 再转换为二进制格式输出时,输出类型为字符串类型。输出的二进制数和BigInteger形式表示的二进制数完全不同。值已经发生改变。

public class Test {
 public static void main(String[] args) {
  
  String thisstrhash = "1000011001111101111100101011111010000110110101110101110001100100";
  String otherstrhash = "0000011001111101101100101011111010000110110101110101111001001100";
  BigInteger thisintegerhash = new BigInteger(thisstrhash);
  BigInteger otherintegerhash = new BigInteger(otherstrhash);
  
  System.out.println("thisstrhash:\t" + thisstrhash);
  System.out.println("otherstrhash:\t" + otherstrhash);
  
  System.out.println();
  
  String intergerTolongBit = Long.toBinaryString(thisintegerhash.longValue());
  
  System.out.println("thisintegerhash intergerTolongBit:\t" +  intergerTolongBit);
  
  System.out.println();
  
  System.out.println("thisintegerhash:\t" + thisintegerhash);
  System.out.println("otherintegerhash:\t" + otherintegerhash);
  
 }
}

输出结果:

thisstrhash: 1000011001111101111100101011111010000110110101110101110001100100
otherstrhash: 0000011001111101101100101011111010000110110101110101111001001100
thisintegerhash intergerTolongBit: 11111110100001000010000111010110000001100011110010101000100
thisintegerhash: 1000011001111101111100101011111010000110110101110101110001100100
otherintegerhash: 11001111101101100101011111010000110110101110101111001001100

结果比较:

String表示的二进制数转换为BigInteger,若二进制数以0开头,则转换为的BigInteger二进制数省掉第一个1前面的所有0。否则,若String表示的二进制数以1开头,则它转化为BigInteger形式的二进制数时,它的二进制形式和String表示时相同,原样输出,值未发生改变。
BigInteger转换为Long类型 -> 再转换为二进制格式输出时,输出类型为字符串类型。输出的二进制数和BigInteger形式表示的二进制数完全不同。值已经发生改变。

1、String表示的二进制数转换为BigInteger,若二进制数以0开头,则转换为的BigInteger二进制数省掉第一个1前面的所有0

String otherstrhash = "0000011001111101101100101011111010000110110101110101111001001100";
  BigInteger otherintegerhash = new BigInteger(otherstrhash);
 System.out.println("otherintegerhash:\t" + otherintegerhash);

输出结果:

otherintegerhash: 11001111101101100101011111010000110110101110101111001001100

2、若String表示的二进制数以1开头,则它转化为BigInteger形式的二进制数时,它的二进制形式和String表示时相同,原样输出,值未发生改变。

String thisstrhash = "1000011001111101111100101011111010000110110101110101110001100100";
 BigInteger thisintegerhash = new BigInteger(thisstrhash);
 System.out.println("thisintegerhash:\t" + thisintegerhash);

输出结果:

thisintegerhash: 1000011001111101111100101011111010000110110101110101110001100100

3、BigInteger转换为Long类型 -> 再转换为二进制格式输出时,输出类型为字符串类型。输出的二进制数和BigInteger形式表示的二进制数完全不同。值已经发生改变。

  String thisstrhash = "1000011001111101111100101011111010000110110101110101110001100100";
   BigInteger thisintegerhash = new BigInteger(thisstrhash);
  String intergerTolongBit = Long.toBinaryString(thisintegerhash.longValue());
  System.out.println("thisintegerhash intergerTolongBit:\t" +  intergerTolongBit);

输出结果:

thisintegerhash intergerTolongBit: 11111110100001000010000111010110000001100011110010101000100

4、以0开头的Integer转化为Long输出,结果完全改变

String otherstrhash = "0000011001111101101100101011111010000110110101110101111001001100";
BigInteger otherintegerhash = new BigInteger(otherstrhash); 
System.out.println(otherintegerhash); 
System.out.println();
System.out.println(Long.toBinaryString(otherintegerhash.longValue()));

输出结果:

11001111101101100101011111010000110110101110101111001001100
1100010011001111000010000111011101011110010110010110010001100

 

你可能感兴趣的:(String表示的二进制数转换为BigInteger,BigInteger转换为Long类型二进制)