zoukankan      html  css  js  c++  java
  • 16进制字符串的相关转换

    public static byte uniteBytes(byte src0, byte src1) {
    byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 }))
    .byteValue();
    _b0 = (byte) (_b0 << 4);
    byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 }))
    .byteValue();
    byte ret = (byte) (_b0 ^ _b1);
    return ret;
    }

    public static byte[] HexString2Bytes(String src) {
    byte[] ret = new byte[8];
    byte[] tmp = src.getBytes();
    for (int i = 0; i < 8; i++) {
    ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
    }
    return ret;
    }

    public static int byte2int(byte[] res) {
    // 一个byte数据左移24位变成0x??000000,再右移8位变成0x00??0000
    int targets = (res[0] & 0xff) | ((res[1] << 8) & 0xff00) // | 表示安位或
    | ((res[2] << 24) >>> 8) | (res[3] << 24);
    return targets;
    }

    /*private Integer hexToInt(String str, int start, int end){
    long res = 0;
    for(int i = start; i < end; i++){
    res = res*16 + Integer.parseInt(str.substring(i,i+1), 16);
    }
    return res;
    }*/

  • 相关阅读:
    内层城循环应用——买衣服
    内外层循环用法
    自定义函数的应用
    少有人走的路 随笔
    拆单发货逻辑
    拆单发货-分布页
    拆单发货-主页
    SP--report存储过程
    关于C#对Xml数据解析
    C#模拟http 发送post或get请求
  • 原文地址:https://www.cnblogs.com/Miami/p/4583232.html
Copyright © 2011-2022 走看看