zoukankan      html  css  js  c++  java
  • C# getHex函数 输入string (length == 2),输出对应 Int hex;

     public int getHex(string src)
            {
                int hex, hex2;
                string [] buf = new string [2]; buf[0] = src.Substring(0,1);
                buf[1] = src.Substring(1,1);
                
                switch (buf[0])
                {
                    case "1": hex = 0x10; break;
                    case "2": hex = 0x20; break;
                    case "3": hex = 0x30; break;
                    case "4": hex = 0x40; break;
                    case "5": hex = 0x50; break;
                    case "6": hex = 0x60; break;
                    case "7": hex = 0x70; break;
                    case "8": hex = 0x80; break;
                    case "9": hex = 0x90; break;
                    case "0": hex = 0x00; break;
                    case "a":
                    case "A": hex = 0xa0; break;
                    case "b":
                    case "B": hex = 0xb0; break;
                    case "c":
                    case "C": hex = 0xc0; break;
                    case "d":
                    case "D": hex = 0xd0; break;
                    case "e":
                    case "E": hex = 0xe0; break;
                    case "f":
                    case "F": hex = 0xf0; break;
                    default: return 0;
                } 
                switch (buf[1])
                {
                    case "1": hex2 = 0x01; break;
                    case "2": hex2 = 0x02; break;
                    case "3": hex2 = 0x03; break;
                    case "4": hex2 = 0x04; break;
                    case "5": hex2 = 0x05; break;
                    case "6": hex2 = 0x06; break;
                    case "7": hex2 = 0x07; break;
                    case "8": hex2 = 0x08; break;
                    case "9": hex2 = 0x09; break;
                    case "0": hex2 = 0x00; break;
                    case "a":
                    case "A": hex2 = 0x0a; break;
                    case "b":
                    case "B": hex2 = 0x0b; break;
                    case "c":
                    case "C": hex2 = 0x0c; break;
                    case "d":
                    case "D": hex2 = 0x0d; break;
                    case "e":
                    case "E": hex2 = 0x0e; break;
                    case "f":
                    case "F": hex2 = 0x0f; break;
                    default: return 0;
                }
                return hex + hex2;  
            }
    

      

  • 相关阅读:
    vxlan 内核实现
    perf 系统调用
    quic NAT
    机器学习在ABR算法中的应用纵览
    清华最新AIOps案例:强化学习,降低网络传输延时
    内核gso
    怎么提高网络应用性能?让DPDK GRO和GSO来帮你!
    网卡VXLAN的offload技术介绍
    Matplotlib中的plt和ax画图的区别
    Task 3: 异常处理(2天)
  • 原文地址:https://www.cnblogs.com/fcar/p/2472947.html
Copyright © 2011-2022 走看看