zoukankan      html  css  js  c++  java
  • 二进制转换成十六进制

    //如"我"字的gb2312编码: 十六进制表示为 ce,十进制表示为206.
            
    //它的演算为: int b=206(11001110)(ce); b>>4=12(1100)(c); b & 0xF (11001110 & 00001111)=14(00001110)(e);
        Byte[] buffer=null;
                    buffer
    =System.Text.Encoding.GetEncoding("GB2312").GetBytes(ChinaStr1);
            
                    
    string str2=ToHexString(buffer) ;
    static char[] hexDigits = {
                                          
    '0''1''2''3''4''5''6''7',
                                          
    '8''9''a''b''c''d''e''f'}
    ;
     
            
    private static string ToHexString(byte[] bytes) 
            
    {
                
    char[] chars = new char[bytes.Length * 4];
                
    for (int i = 0; i < bytes.Length; i++
                
    {
                    
    int b = bytes[i];
                    chars[i 
    * 4 ]='\\';
                    chars[i 
    * 4 + 1]='\'';
                    chars[i * 4 + 2= hexDigits[b >> 4];
                    chars[i 
    * 4 + 3= hexDigits[b & 0xF];
                    
                }

                
    return new string(chars);
            }
  • 相关阅读:
    linux基础名词
    计算机基础
    c++ 构造函数
    c++ stdafx.h、targetver.h文件
    centos7初步命令
    mysql 操作表的语句
    后台返回API数据格式
    nginx相关知识
    js复制内容到剪贴板格式化粘贴到excel中
    PHP开启错误提示
  • 原文地址:https://www.cnblogs.com/furenjun/p/326500.html
Copyright © 2011-2022 走看看