Any conversion between Java and any binary

Source: Internet
Author: User

Directly on the code:

public class Main {public static void main (string[] args) {//TODO auto-generated method StubSystem.out.println ("decimal conversion to other input System: "); int x = 123;      String str1 = integer.tohexstring (x); 10 binary converted to 16 binary string System.out.println (STR1);     String str2 = integer.tooctalstring (x); 10 binary converted to 8 binary string System.out.println (STR2);    String STR3 = integer.tobinarystring (x); 10 binary converted to 2 binary string System.out.println (STR3);  String STR4 = integer.tostring (123456,7);  10 binary converted to 7 binary string///string STR4 = integer.tostring (i,x);     The 10 binary number I is converted to the X-binary string System.out.println ("Other system converts to decimal:"), int y1= integer.valueof ("FFFF", 16); 16 binary converted to 10 binary System.out.println (y1), int y2=integer.valueof ("776", 8); 8 binary converted to 10 binary System.out.println (y2), int y3=integer.valueof ("0101", 2); 2 binary converted to 10 binary System.out.println (y3), int y4=integer.valueof ("101", 7); 7 binary converted to 10 binary System.out.println (y4);///integer.valueof ("str", x); You can convert any string str into an X-System.out.println ("Other possible function:"),//static int parseint (string s, int radix)// Uses the cardinality specified by the second argument to resolve the string argument toA signed integer. int n = integer.parseint ("776", 8); 8 binary to 10 binary System.out.println (n);///integer.valueof () returns an "Integer object" and Integer.parseint () returns an "int value" difference in that the return value is different Basic knowledge, other non-10 binary number of the save, basically are in the form of a string///Example: 7 to 8 binary conversion string q = "6523"; 7 binary strings String b = integer.tostring (integer.valueof (q,7), 8);///So 7 binary becomes 8 binary}}

Any conversion between Java and any 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.