python--simple implementation of decimal to 16, eight or two binary conversion

Source: Internet
Author: User

#coding: Utf-8 '      recently looking at data structure ———— stack     This is also a "  teaching  " written by the Great Gods abroad      decimal number converted to ———— 16, eight or two "# " a stackclass stack:    by object-oriented class  def __init__ (self):        self.items = []     def isempty (self):        return  Self.items == []    def push (Self, item):         return self.items.append (item)     def pop (self):         return self.items.pop ()     def peek ( Self):         return self.items[len (Self.items) -1]     def size (self):         return len (Self.items) #   ———— "base" as a binary def ba by functionSeconverter (decnumber, base):    digits =  ' 0123456789ABCDEF      s = stack ()     a =  '     while  decnumber > 0:        rem = decnumber %  base        s.push (REM)          decnumber //= base    while not s.isempty ():         a += digits[s.pop ()]    return aprint  baseconverter (233, 16)


python--simple implementation of decimal to 16, eight or two binary conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.