This is the 26th day of my participation in the August Text Challenge.More challenges in August

A practical tips every day, base conversion is very simple

Base conversion, belongs to the basic skill, in Java to implement base conversion is very simple, can be very simple implementation, next let’s look at its use posture

1. ToString implements base conversion

Integer/Long#toString(int I, int radix) can convert any base Integer to any other base Integer

  • The first parameter: the number to convert
  • Second argument: converted base bit

Conversion from hexadecimal to decimal

Integer.toString(0x12.10)
Copy the code

Octal to octal

Integer.toString(012.10)
Copy the code

Octal to binary

Integer.toString(012.2)
Copy the code

2. Switch from decimal to binary

In addition to using the pose above, you can implement binary conversion directly using toBinaryString

Integer.toBinaryString(2)
Long.toBinaryString(2)
Copy the code

3. Decimal to octal

Integer/Long#toOctalString: switch to octal

Integer.toOctalString(9)
Copy the code

4. Convert from decimal to hexadecimal

Integer/Long#toHexString: convert to hexadecimal

Integer.toHexString(10)
Copy the code

Series of blog posts:

  • Practical tip 1: String placeholder replacement -JDK version
  • Practice Tip 2: Array and list are rotated
  • Practice Tip 3: String and container transfer
  • Practical tip 4: Elegant string concatenation implementation
  • Practice tip 5: Hump and underline turn each other
  • Practice Tip 6: Special use of enumeration
  • Practice Tip 7: Sort carefully
  • Practice tip 8: Specify the initial size of the container
  • List. SubList is used incorrectly StackOverflowError
  • Practice Tip # 10: Immutable containers
  • Practice Tip 11: Array copy
  • Practice Tip 12: Number formatting

II. The other

1. A gray Blog:liuyueyi.github.io/hexblog

A gray personal blog, recording all the study and work in the blog, welcome everyone to go to stroll

2. Statement

As far as the letter is not as good, the above content is purely one’s opinion, due to the limited personal ability, it is inevitable that there are omissions and mistakes, if you find bugs or have better suggestions, welcome criticism and correction, don’t hesitate to appreciate

  • Micro Blog address: Small Gray Blog
  • QQ: a gray /3302797840
  • Wechat official account: One Grey Blog