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);
            }
  • 相关阅读:
    缓存服务Ehcache方案
    sql的一点总结<一>
    消息队列-ActiveMQ
    Kettle数据抽取解决方案
    在VMware上安装VMTools
    数组去重方法
    横向tab计算滚动位置
    无高度内容垂直居中
    常见富文本处理方法
    极简触感反馈Button组件
  • 原文地址:https://www.cnblogs.com/furenjun/p/326500.html
Copyright © 2011-2022 走看看