zoukankan      html  css  js  c++  java
  • 几种不同的字符编码方式

    1.gbk

    gbk编码格式中一个中文占两个字节,英文占一个字节

    String s = "你好ABC";
    byte[] bytes = s.getBytes("gbk");
    //gbk编码中文占两个字节,英文占一个字节
    for (byte b : bytes) {
    //把字节转化成int以16进制显示(只填充了int的低八位),与0xff(1111 1111)相与只取低八位。
    System.out.print(Integer.toHexString(b & 0xff)+" ");
    }

    执行结果:

    c4 e3 ba c3 41 42 43 

    2.utf-8

    byte[] bytes1 = s.getBytes("utf-8");
    //utf-8中文占三个字节,英文占1个字节
    for (byte b : bytes1) {
    System.out.print(Integer.toHexString(b & 0xff)+" ");
    }
    System.out.println();

    执行结果:

    e4 bd a0 e5 a5 bd 41 42 43

    3.utf-16be

    //java是双字节编码utf-16be(编译形成class文件后),中文占两个字节,英文占两个字节
    byte[] bytes2 = s.getBytes("utf-16be");
    for (byte b : bytes2) {
    System.out.print(Integer.toHexString(b & 0xff)+" ");
    }

    执行结果:

    4f 60 59 7d 0 41 0 42 0 43 

  • 相关阅读:
    C++基类的析构函数定义为虚函数的原因
    android的学习网站
    QT显示url图片
    Ubuntu安装JDK
    linux下打包压缩和解压命令
    嵌入式目录
    QT pri 文件的作用
    QT pro文件详细写法+实例
    Computer(树的直径做法)
    树的直径
  • 原文地址:https://www.cnblogs.com/simple96/p/7222040.html
Copyright © 2011-2022 走看看