Home > Java > javaTutorial > Summary of Java's medium-base conversion functions

Summary of Java's medium-base conversion functions

黄舟
Release: 2017-07-17 10:21:40
Original
2160 people have browsed it

The following editor will bring you a detailed explanation of the hexadecimal conversion function based on Java. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

Convert decimal to hexadecimal:

Integer.toHexString(int i)
Copy after login

Convert decimal to octal

Integer.toOctalString(int i)
Copy after login

Convert decimal to binary

Integer.toBinaryString(int i)
Copy after login

Convert hexadecimal to decimal

Integer.valueOf("FFFF",16).toString()
Copy after login

Convert octal to decimal

Integer.valueOf("876",8).toString()
Copy after login

Convert binary to decimal

Integer.valueOf("0101",2).toString()
Copy after login

Is there any way to directly convert 2 ,8,16 hexadecimal directly converted to decimal?

java.lang.Integer类 
parseInt(String s, int radix)
Copy after login

Parses the string argument into a signed integer using the base specified by the second argument.

examples from jdk: 
parseInt("0", 10) returns 0 
parseInt("473", 10) returns 473 
parseInt("-0", 10) returns 0 
parseInt("-FF", 16) returns -255 
parseInt("1100110", 2) returns 102 
parseInt("2147483647", 10) returns 2147483647 
parseInt("-2147483648", 10) returns -2147483648 
parseInt("2147483648", 10) throws a NumberFormat
Exception
 
parseInt("Kona", 10) throws a NumberFormatException 
parseInt("Kona", 27) returns 411787
Copy after login

Base conversionHow to write (two, eight, sixteen) without algorithm

Integer.toBinaryString 
Integer.toOctalString 
Integer.toHexString
Copy after login

The above is the detailed content of Summary of Java's medium-base conversion functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template