欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Python任意字符串轉(zhuǎn)16, 32, 64進(jìn)制的方法

系統(tǒng) 1809 0

Python字符串轉(zhuǎn)數(shù)字

            
  import binascii

  s = 'test123456test'
  str_16 = binascii.b2a_hex(s.encode('utf-8')) # 字符串轉(zhuǎn)16進(jìn)制
  print(str_16)

  def baseN(num, b):
    return ((num == 0) and "0") or \
        (baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])

  num_10 = int(str_16, 16) # 16進(jìn)制轉(zhuǎn)10進(jìn)制
  print(num_10)

  str_32 = baseN(num_10, 32) # 10進(jìn)制轉(zhuǎn)32進(jìn)制
  print(str_32)

  num_10_2 = int(str_32, 32) # 32進(jìn)制轉(zhuǎn)10進(jìn)制
  print(num_10_2)

  num_16 = hex(num_10) # 10進(jìn)制轉(zhuǎn)16進(jìn)制數(shù)
  print(num_16)

  ss = str_16.decode('hex') # 16進(jìn)制串轉(zhuǎn)字符串
  print(ss)
          

執(zhí)行結(jié)果

            
7465737431323334353674657374
2360797289681380981751517517542260
1q6asrk64p36d1l6pq6asrk
2360797289681380981751517517542260
0x7465737431323334353674657374L
test123456test
          

10進(jìn)制轉(zhuǎn)n進(jìn)制

            
def base10toN(num,n):
  """Change a to a base-n number.
  Up to base-36 is supported without special notation."""
  num_rep={10:'a',
     11:'b',
     12:'c',
     13:'d',
     14:'e',
     15:'f',
     16:'g',
     17:'h',
     18:'i',
     19:'j',
     20:'k',
     21:'l',
     22:'m',
     23:'n',
     24:'o',
     25:'p',
     26:'q',
     27:'r',
     28:'s',
     29:'t',
     30:'u',
     31:'v',
     32:'w',
     33:'x',
     34:'y',
     35:'z'}
  new_num_string=''
  current=num
  while current!=0:
    remainder=current%n
    if 36>remainder>9:
      remainder_string=num_rep[remainder]
    elif remainder>=36:
      remainder_string='('+str(remainder)+')'
    else:
      remainder_string=str(remainder)
    new_num_string=remainder_string+new_num_string
    current=current/n
  return new_num_string
          

進(jìn)階版

            
  def baseN(num, b):
    return ((num == 0) and "0") or \
       (baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
          

64進(jìn)制

            
  def encode_b64(n):
    table = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'
    result = []
    temp = n
    if 0 == temp:
      result.append('0')
    else:
      while 0 < temp:
        result.append(table[temp % 64])
        temp /= 64
    return ''.join([x for x in reversed(result)])


  def decode_b64(str):
    table = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5,
         "6": 6, "7": 7, "8": 8, "9": 9,
         "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16,
         "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23,
         "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30,
         "v": 31, "w": 32, "x": 33, "y": 34, "z": 35,
         "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42,
         "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49,
         "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56,
         "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61,
         "-": 62, "_": 63}
    result = 0
    for i in xrange(len(str)):
      result *= 64
      result += table[str[i]]
    return result
          

Java字符串轉(zhuǎn)數(shù)字

            
BigInteger integer = new BigInteger(hexString.toString(), 16);
integer.toString(32);
          
            
import java.math.BigInteger;

public class Main {
 public static void main(String[] argv) throws Exception {
  BigInteger bi = new BigInteger("1023");
  bi = new BigInteger("1111111111", 2); 
  String s = bi.toString(2); 
  System.out.println(s);
  bi = new BigInteger("1000", 8);

  System.out.println(s = bi.toString(8));

  bi = new BigInteger("1023"); 
  s = bi.toString(); 
  System.out.println(s);

  bi = new BigInteger("3ff", 16); 
  s = bi.toString(16); 
  System.out.println(s);
 }
}
          

以上這篇Python任意字符串轉(zhuǎn)16, 32, 64進(jìn)制的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美一区二区三区在线播放 | 麻豆精品视频在线 | 黄色av一区 | 四虎影视最新网站在线播放 | 成人激情视频在线观看 | 99re在线精品| 欧美日韩成人一区二区 | 日本欧美一区二区三区视频 | 人人看人人干 | 深夜影院破解版免费vip | 天堂动漫 | 欧美精品一区二区三区免费播放 | 91精品国产一区二区三区 | 永久免费mv网站入口 | 色综合综合色 | 超级碰在线视频 | 三级三级三级a三级三级 | 亚洲免费观看视频 | 久草手机在线播放 | 国产成人一级 | 天天干干 | 久草免费小视频 | 欧美大片在线看免费观看 | 九九香蕉视频 | 精品黄网| 日韩国产在线观看 | 日韩在线aⅴ免费视频 | 久草精品在线 | 三极片在线观看 | 手机国产日韩高清免费看片 | 色拍拍欧美视频在线看 | 欧美成人精品久久精品 | 九九资源站 | 亚洲精品久久久久久国产精华液 | 国产一级淫| 中文字幕亚洲综合 | 中文字幕免费 | 欧美激情欧美激情在线五月 | 9久9久女女免费精品视频在线观看 | 九九热在线免费观看 | 亚洲国产天堂久久精品网 |