Home > Net >  Java and c # BigInteger methods
Java and c # BigInteger methods

Time:05-24

Background: recent turn in a c # do Java project

The method of c #
BigInteger. Parse (string val, NumberStyles HexNumber)
BigInteger. Parse (" FFFFFFFFFFFEA070, "NumberStyles. HexNumber) is the result of the - 90000
Use [note: if the number of top two hexadecimal string is equal to or greater than 0 x80, then the Parse () method will be the first as the sign bit, namely it is stored as a negative number -- -- -- -- -- found on the Internet]



Then this method in the Java
New BigInteger (String val, int radix)
New BigInteger (" FFFFFFFFFFFEA070 ", 16) is the result of the 18446744073709461616


Two methods are hexadecimal to decimal (I should say yes!), but the result is not the same as



How to change the Java methods above results to the same as the result of the c #


May be expressed is not very clear, forgive me...

CodePudding user response:

Types of Java byte is signed (Java is no unsigned types of data), range: - 0128 ~ 127

C # numerical byte is unsigned types, range: 0 ~ 255

Solution:
C # a sbye is signed, use sbye [] to replace bye [], conversion issues are resolved,

CodePudding user response:

Use BigInteger. The Parse () convert hexadecimal string for decimal Numbers have two points:


1, hex string cannot "0 x" or "& amp; H "prefix for
2, if the number of top two hexadecimal string is equal to or greater than 0 x80, then the Parse () method will be the first as the sign bit, namely it is stored as a negative number, if you need to put this hexadecimal string parsing is positive, the need to add "0" in front of the string,
If you sink down, look carefully, there will be no this question

CodePudding user response:

reference 1st floor morliz son hin reply:
Java byte is symbols (Java is no unsigned types of data), range: - 0128 ~ 127

C # numerical byte is unsigned types, range: 0 ~ 255

Solution:
C # a sbye is signed, use sbye [] to replace bye [], transformation problem is resolved,

B: well... My purpose is how to rewrite the Java method with the methods of the c #... Because it is the system of class I do not see the source code, don't know how to modify, I'm a c # small white ha ha ha ha ha ha

CodePudding user response:

Popular Java, c # has not yet been born
It should be:
The c # methods rewritten into like Java methods

CodePudding user response:

Xuzuning
reference 4 floor response:
popular Java, c # has not yet been born
It should be:
C # method rewritten into like Java method


Ha ha ha ha I already solved the problem, wrote on his blog

CodePudding user response:

Just look at the c # use what type, it is good to do the numerical type conversion processing,
Not much of a problem,
  •  Tags:  
  • C#
  • Related