Java example of converting an integer into binary code
•
Java
The method of converting an integer to binary:
1method 1: use BigInteger class:
2 method 2: use integer toBinaryString():
As described above, an integer can indeed be converted into binary, but the disadvantage is that when a number is converted into binary, it is less than 8 bits, and 0 will not be automatically supplemented; Therefore, when you want to obtain an 8-bit binary number, you need to add judgment:
summary
The above is all about the example of Java converting an integer into binary code. I hope it will be helpful to you. Interested friends can continue to refer to other related topics on this site. If there are deficiencies, please leave a message to point out. Thank you for your support!
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码