Conversion between hexadecimal in java and java hexadecimal conversion

Source: Internet
Author: User
Tags binary to decimal

Conversion between hexadecimal in java and java hexadecimal conversion

// Convert decimal to other hexadecimal

Integer. toHexString (10); // converts 10 to hexadecimal format, and returns the string type.

Integer. toOctalString (10); // convert 10 to octal and return the string type.

Integer. toBinaryString (10); // convert 10 to binary and return the string type.

 

// Convert other hexadecimal values to decimal values

 

// Convert hexadecimal to decimal, for example, 0 xFFFF

Integer. valueOf ("FFFF", 16). toString (); // the valueOf () method returns the Integer type, and the toString () method is called to return the string.

Integer. parseInt ("FFFF", 16); // returns the basic int data type.

Integer. toString (0 xFFFF); // This method can be used to directly input the basic data type that represents a hexadecimal number. The method returns a string.

 

// Convert octal to decimal, for example, 017

Integer. valueOf ("17", 8). toString (); // the valueOf () method returns the Integer type. Call toString () to return the string.

Integer. parseInt ("17", 8); // returns the basic int data type.

Integer. toString (017); // This method can be used to directly input the basic data type representing the octal number. The method returns a string.

 

// Convert binary to decimal, for example: 0101

Integer. valueOf ("0101", 2). toString (); // the valueOf () method returns the Integer type. Call toString () to return the string.

Integer. parseInt ("0101", 2); // returns the basic int data type.

 

// For the conversion between binary, octal, and hexadecimal, You can first convert it to decimal, and convert it in the corresponding method of convert it into multi-hexadecimal

// For example, convert hexadecimal 0xFF to binary

Integer. toBinaryString (Integer. valueOf ("FF", 16 ));

// Or

Integer. toBinaryString (Integer. parseInt ("FF", 16 ));

 

// For the input string that represents the hexadecimal format, you must first intercept the number substring and convert it to decimal using the valueOf () or parseInt () method.

// For example, enter 0xFF

String s = "0xFF ";

Integer. valueOf (s. subString (2, s. length (), 16 );

 

// For the valueOf method, it can be used for packing basic data types and conversion from multi-hexadecimal to decimal.

 

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.