In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "knowledge Summary of Python binary conversion". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Convert an integer to an arbitrary base
The daily operation is based on the decimal system, but no matter what the base is, it can be converted by a fixed formula (n is an integer, base is a cardinality)
N / / base: get the next divisor (size reduced)
N% base: get the current remainder
For example: calculation 769 converted to decimal
Problem decomposition
Basic end condition: the remainder is less than the binary base base (loop end condition)
In fact, to put it bluntly, it is to use recursion to realize the binary conversion in mathematics, and recursion is to replace the loop.
When understanding recursion, don't think too complicated, directly expand the place of the recursive call into the result returned by each loop.
Return convert_base (number//base, base) + convert_ string [numbering% base]
This code is the part of a recursive call, expanded to understand (recursion is instead of a loop), which is step by step equivalent to
It can also be understood like this:
This is the end of the summary of the knowledge of Python binary conversion. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.