• 编码的进阶


    编码的进阶

    • ASCII码:包含英文字母,数字,特殊字符与01010101对应关系。

      a 01000001 一个字符一个字节表示。

    • GBK:只包含本国文字(以及英文字母,数字,特殊字符)与0101010对应关系。

      a 01000001 ascii码中的字符:一个字符一个字节表示。

      中 01001001 01000010 中文:一个字符两个字节表示。

    • Unicode包含全世界所有的文字与二进制0101001的对应关系。

      a 01000001 01000010 01000011 00000001

      b 01000001 01000010 01100011 00000001

      中 01001001 01000010 01100011 00000001

    • UTF-8:包含全世界所有的文字与二进制0101001的对应关系(最少用8位一个字节表示一个字符)。

      a 01000001 ascii码中的字符:一个字符一个字节表示。

      To 01000001 01000010 (欧洲文字:葡萄牙,西班牙等)一个字符两个字节表示。

      中 01001001 01000010 01100011 亚洲文字;一个字符三个字节表示。

    1. 不同的密码本之间能否互相识别?不能。

    2. 数据在内存中全部是以Unicode编码的,但是当你的数据用于网络传输或者存储到硬盘中,必须是以非Unicode编码(utf-8,gbk等等)。

    • 英文:

      str: 'hello '

      ​ 内存中的编码方式: Unicode

      ​ 表现形式: 'hello'

      bytes :

      ​ 内存中的编码方式: 非Unicode

      ​ 表现形式:b'hello'

    中文:

    ​ str:

    ​ 内存中的编码方式: Unicode

    ​ 表现形式:'中国'

    ​ bytes :

    ​ 内存中的编码方式: 非Unicode # Utf-8

    ​ 表现形式:b'xe4xb8xadxe5x9bxbd'

    # str ---> bytes
    # s1 = '中国'
    # b1 = s1.encode('utf-8')  # 编码
    # print(b1,type(b1))  # b'xe4xb8xadxe5x9bxbd'
    # # b1 = s1.encode('gbk')  # 编码  # b'xd6xd0xb9xfa' <class 'bytes'>
    # # bytes---->str
    # b1 = b'xe4xb8xadxe5x9bxbd'
    # s2 = b1.decode('utf-8')  # 解码
    # print(s2)
    
    # gbk ---> utf-8
    b1 = b'xd6xd0xb9xfa'
    s = b1.decode('gbk')
    # print(s)
    b2 = s.encode('utf-8')
    print(b2)  # b'xe4xb8xadxe5x9bxbd'
    
    
  • 相关阅读:
    【转】【SEE】基于SSE指令集的程序设计简介
    【转】【Asp.Net】asp.net服务器控件创建
    ControlTemplate in WPF ——ScrollBar
    ControlTemplate in WPF —— Menu
    ControlTemplate in WPF —— Expander
    ControlTemplate in WPF —— TreeView
    ControlTemplate in WPF —— ListBox
    ControlTemplate in WPF —— ComboBox
    ControlTemplate in WPF —— TextBox
    ControlTemplate in WPF —— RadioButton
  • 原文地址:https://www.cnblogs.com/wyh0717/p/12911154.html
Copyright © 2020-2023  润新知