Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2009-02-17 06:02:41
Size: 574
Editor: jigloo
Comment:
Revision 4 as of 2009-12-25 07:12:33
Size: 539
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
[[TableOfContents]] <<TableOfContents>>
Line 7: Line 7:
[[Include(ZPyUGnav)]] <<Include(ZPyUGnav)>>
Line 10: Line 10:
>>> bin = lambda n:''.join({'0':'0','1':'1','2':'10','3':'11','4':'100','5':'101','6':'110','7':'111'}[x] for x in oct(n)[1:]) '' >>> bin = lambda n:'0b'+''.join({'0':'0','1':'1','2':'10','3':'11','4':'100','5':'101','6':'110','7':'111','8':'1000','9':'1001','a':'1010','b':'1011','c':'1100','d':'1101','e':'1110','f':'1111'}[x] for x in hex(n)[2:].rstrip('L'))''
Line 15: Line 15:
'''1111111111111111' '' "''11111111111111111' ''
Line 19: Line 19:
||<style="vertical-align: top;">[[PageComment2]]||<style="vertical-align: top;">[:MiscItems/2009-02-17/PageCommentData:PageCommentData] ||

一句话将int转化为二进制字符串

>>> bin = lambda n:'0b'+.join({'0':'0','1':'1','2':'10','3':'11','4':'100','5':'101','6':'110','7':'111','8':'1000','9':'1001','a':'1010','b':'1011','c':'1100','d':'1101','e':'1110','f':'1111'}[x] for x in hex(n)[2:].rstrip('L'))

>>> bin(65535)

"11111111111111111'


  • 反馈

MiscItems/2009-02-17 (last edited 2009-12-25 07:12:33 by localhost)