Interpretation of integer method for Java source code parsing

Interpretation of tounsignedstring method

We can see that there is such a method in integer to convert int to unsigned string, but several points are not very clear. After querying the data, we understand it. The interpretation is as follows:

The parameter shift here represents binary. If it is binary, shift is 2 and octal is 8. Accordingly, its mask is calculated as 1 and 7. The corresponding characters in the digits array are continuously extracted through mask and I.

In I, every time I performs a logical right shift operation, the highest bit is supplemented with zero, so that I will become 0 after continuous logical right shift

In addition, using do while prevents the buf array from obtaining its value when I itself is 0.

Interpretation of toString method

Interpretation of highestonebit method

This method is very interesting. I calculated it myself, and then I understood its essence. The function of this method is to find the value of the integer represented by the largest bit of an integer. This function is realized by displacement. Let's take a simple example. For 128, the binary is 10 million. Take him as an example:

Shift 1 bit 1000 0000 0100 0000 | ------------ shift 2 bits 1100 0000 0011 0000 | ------------ shift 4 bits 1111 0000 1111 0000 | ------------ shift 8 bits 1111 1111 0000 0000 | ------------ shift 16 bits 1111 1111 0000 0000 | ------------ 1111 1111 1111

The final result, as you can see, is that all the following bits are filled with 1, and all the following bits are subtracted to get the integer represented by the highest bit.

Bitcount method parsing

This method really wasted a long time of research, and later I got a general idea: the first line is to group the binary bits of integer into two, and then count the number of 1 in these two bits. I don't know how this formula came from, but it is really like this. The second line is to group the binary bits of the integer into four groups, and then calculate the shift addition in the segment, that is, 1001 - > 10 + 01 = 11 is equivalent to three ones. The third line is to group the binary bits of the integer into eight groups, and then add the shift in a similar way. Of course, it is realized here through some specific shifts and and operations. Next is a group of 16 and 32. Finally, the statistics are merged into the statistical values represented by the last few digits.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>