In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
When computer students start to learn, they all have to come into contact with the conversion between binary systems, such as binary, decimal, octal, hexadecimal, and so on. This is very boring. Don't be fooled. Let's do it one by one today. Look at how binary and decimal convert each other. The time complexity of this algorithm is O (1), what a surprise! The algorithm I think of is to divide n by 2 until n becomes 0, and if the remainder is not 0 along the way, then n is not a power of 2.
So the time complexity of the algorithm is O (log2 (n)). But who knows that after using binary bit operation, it immediately becomes O (1), which is really incredible. Why is there such an ingenious algorithm, or is it because the binary number has only two digits, which can perform bit logic operations. 1. Binary conversion decimal mode 1:
Use the BigInteger class to build decimal data.
How do binary and decimal systems convert each other?
2. Binary conversion decimal mode 2:
Use the Integer.parseInt method for binary conversion to decimal.
How do binary and decimal systems convert each other?
3. Binary conversion decimal mode 3:
Use custom mathematical algorithm rules for binary conversion to decimal.
How do binary and decimal systems convert each other?
4. Decimal conversion binary mode 1:
Use the BigInteger class to build decimal data and convert it to binary.
How do binary and decimal systems convert each other?
5. Binary conversion decimal mode 2:
Use the Integer.parseInt method to convert decimal to binary. First, calculate the number of 1s in the binary of a number
Int NumberOfOne (int n)
{
Int count = 0
While (n)
{
+ + count
N = n & (n Mel 1)
}
Return count
}
Summary and analysis: subtract one from an integer, and then do and operate with the original integer, which will turn the rightmost 1 into 0, so the number of 1s in the binary representation of an integer can be done as many times as possible.
2. Use a sentence to determine whether an integer is to the integer power of 2. Analysis: if an integer is to the power of 2, then one and only one bit in its binary representation is 1, while all other bits are 0.
3. Input two integers m and n to calculate the number of bits in the binary representation of m to get n. Analysis: the first step is to find the XOR (^) of the two numbers, and the second part is to calculate the number of digits in the XOR result.
-
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.