Conversion between binaries in Java

Source: Internet
Author: User
Tags binary to decimal

Decimal to other binary

Integer.tohexstring (10); Convert 10 to 16, return string type

Integer.tooctalstring (10); Convert 10 to octal, return string type

Integer.tobinarystring (10); Convert 10 to binary, return string type

Other decimal in binary

hexadecimal to decimal, for example: 0xFFFF

Integer.valueof ("FFFF", +). toString (); The ValueOf () method returns an integer type, calling ToString () to return a string

Integer.parseint ("FFFF", 16); Returns the INT basic data type

Integer.tostring (0xFFFF); The method can pass directly to the base data type that represents the hexadecimal number, and the method returns a string

octal decimal, for example: 017

Integer.valueof ("n", 8). toString (); The ValueOf () method returns an integer type, calling ToString () to return a string

Integer.parseint ("17", 8); Returns the INT basic data type

Integer.tostring (017); The method can pass directly to the base data type that represents the octal number, and the method returns a string

Binary to decimal, for example: 0101

Integer.valueof ("0101", 2). ToString (); The ValueOf () method returns an integer type, calling ToString () to return a string

Integer.parseint ("0101", 2); Returns the INT basic data type

Conversions between binary, octal, and hexadecimal can be converted to decimal and converted using decimal to multi-binary method

For example, turning hex 0xFF into binary

Integer.tobinarystring (integer.valueof ("FF", 16));

Or

Integer.tobinarystring (Integer.parseint ("FF", 16));

For input strings that represent hexadecimal, you need to intercept the number substring, and then use the valueof () or parseint () method to convert to decimal.

For example, enter 0xFF

String s = "0xFF";

Integer.valueof (S.substring (2,s.length ()), 16);

For the valueof method, it can be used for boxing of the base data type and for conversions between the decimal and the binary.

Conversion between binaries in Java

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.