Reciprocal conversions between decimal and other binary

Source: Internet
Author: User

One, the conversion of the binary into decimal

int Integer.parseint (String s,int radix); Method use:
parseint ("0", 10) returns 0
parseint ("473", 10) returns 473
parseint ("0", 10) returns 0
parseint ("-ff", 16) return-255
parseint ("1100110", 2) returns 102
parseint ("2147483647", 10) returns 2147483647
parseint ("2147483648", 10) return-2147483648
parseint ("2147483648", 10) throws NumberFormatException
parseint ("99", 8) throws NumberFormatException
parseint ("Kona", 10) throws NumberFormatException
parseint ("Kona", 27) return 411787

Parameters:
S-String containing the integer representation to parse
Radix-the cardinality used when analyzing S.
Return:
An integer that is represented by a string parameter of the specified cardinality.
Thrown:
NumberFormatException-If String does not contain an int that can be parsed.
It can be understood that the second parameter represents some kind of a binary of the first parameter, such as:
Integer.parseint ("0101", 2);//indicates that the string is a binary and then converts it to a 10-binary int type to return

Integer integer.valueof (Strings, int radix), method use consistent.

Two or 10 binary conversion to other binary:

String Integer. tobinarystring (int i);
Returns the string form of an integer parameter as a binary unsigned integer.
Integer.tobinarystring (10);//return: 1010
String Integer. tooctalstring (int i);
Returns the string form of an integer parameter as an octal unsigned integer.
Integer.tooctalstring (10);//return: 12
String Integer. tohexstring (int i);
Returns a string form of an integer argument as an unsigned 16-based integer.
Integer.tohexstring (10);//return: A

(You can transition between these two methods if you want to convert between other binaries )

Reciprocal conversions between decimal and other binary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.