Android binary conversion to each other

Source: Internet
Author: User

Convert byte to 16 binary

public static String Getbyte2str (Byte b) {

byte[] buff = new byte[2];

Buff[0] = mhex[(b >> 4) & 0x0f];

BUFF[1] = mhex[b & 0x0f];

return new String (buff);

}

private static final byte[] Mhex = "0123456789ABCDEF". GetBytes ();

16 binary conversion to 10 binary

int integerstate = integer.valueof (Getbyte2str (macstate), 16);

10 binary conversion to 2 binary string

String s=integer.tobinarystring (integerstate); Binary string

2 binary string converted to 10 binary

String AA = "1010";
Integer f = integer.parseint (aa,2);

In Java, the default is decimal when declaring numbers, you can precede a number with a symbol to indicate that the number is octal "preceded by 0 (0)" or hexadecimal "preceded by 0x (0 x)".

Java's integer wrapper class integer and long provide the ToString (int i,int radix) static method, which converts an arbitrarily-entered integer into another binary integer.

Use the Tobinarystring method of integer or long to convert integers to binary.

Converts an integer to octal using the Tooctalstring method of an integer or long.

Use the Tohexstring method of integer or long to convert integers to 16 binary.

Use the ToString (int i) method of an integer or long to convert other binary integers to a string representation of a decimal integer.

Android binary conversion to each other

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.