In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to convert large numbers to decimal numbers in Java. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
First of all, it is necessary to clarify the conversion rules: if a large number changes to a decimal number, the extra high part will be truncated. For example, if int accounts for 4 byte (32 bit) and byte accounts for 1 byte (8bit), then the int will be converted to byte, and the 24 bit with high int position will be truncated.
Example 1:
Int b = 233; / / positive integer strong turn System.out.println ((byte) b) / / original code: 0000 0000 0000 1110 1001 picket (memory): 0000 0000 0000 1110 1001ax / positive original code, inverse code, complement code are all the same / / intercept. / / complement code (after intercept-memory): 11101001max / the highest bit is 1, which means it is negative. Therefore, when displaying, you also need to convert. / / reverse code: 1110 1000 / / original code: 1001 0111 / / 16 "4" 2 "1 =-23 (note that the symbol bit is 1, it is negative)
Example 2:
Int b =-233; / / negative integer strong turn System.out.println ((byte) b) / / original code: 1000 0000 0000 0000 1110 1001 / / because it is a negative number, the symbol bit is 1 / / inverse code: 1111 1111 1111 0001 1001 / / the symbol bit remains the same. Other bits reverse / / complement (memory): 1111 1111 1111 0001 0111 / / the complement of the negative number is equal to its inverse code + 1 / / intercept. / / complement (intercepted-memory): 0001 0111 / / the highest bit is 0, which means it is a positive number. the source code, inverse code and complement code of positive numbers are all the same / / original code: 0001 0111 / 16 "4" 2 "1 = 23.
Note:
1. When the number is calculated in memory, it is always in the form of complement, but when it is displayed to our users, it is displayed in the form of original code, so it must be converted into the form of complement before operation. 2. Int to byte, truncating 24 bit of high order, int to short, truncating 16 bit of high order, and so on.
About the mandatory type in Java how to convert large numbers to decimals is shared here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.