zoukankan      html  css  js  c++  java
  • python基本语法1.1--十进制与十六进制数之间的相互转换

    #大端与小端
    print
    ((1024).to_bytes(2, byteorder = 'big')) print((65536).to_bytes(8, byteorder = 'little'))

    #有符号与无符号 print((-1024).to_bytes(4, byteorder = 'big', signed = True))#b'xffxffxfcx00' print((-1024).to_bytes(4, byteorder = 'little', signed = True))#b'x00xfcxffxff' #异常现象(把有些数字直接根据ASCII码表翻译过来了) print((3124).to_bytes(2, byteorder = 'big')) # why x0c4 => x0c + 4(0x34) print((3140).to_bytes(2, byteorder ='little')) # why Dx0c => D(0x44) + 0x0c #把十进制转换成十六进制 print('%x' % 3345) #d11 print('%x' % 3124) #c34

    #把十六进制转换成十进制 print(0xd11) #3345 print(0xc34) #3124

    b = b'china us' print(type(b)) #<class 'bytes'>
    #将其他编码的字符串转换成Unicode编码
    s = b.decode() print(s)#china us

    #将Unicode编码转换成其他进制编码 print(s.encode())#b'china us'
  • 相关阅读:
    杭电2007
    杭电 2004
    杭电2005
    杭电2001
    杭电 2000
    Section One
    杭电oj 1002
    杭电oj 1001
    JavaScript高级程序设计第14章表单脚本 (学习笔记)
    JavaScript高级程序设计(学习笔记)
  • 原文地址:https://www.cnblogs.com/xiaoyingying/p/7689802.html
Copyright © 2011-2022 走看看