java十六进制字符串高低位转换_java如何判断将一个16进制字符串的位置对调刚好与另一个16进制字符串相等-CSDN博客

如“1A2B”转“2B1A”。

    public static String reverseHex(String hex) {
        char[] charArray = hex.toCharArray();
        int length = charArray.length;
        int times = length / 2;
        for (int c1i = 0; c1i < times; c1i += 2) {
            int c2i = c1i + 1;
            char c1 = charArray[c1i];
            char c2 = charArray[c2i];
            int c3i = length - c1i - 2;
            int c4i = length - c1i - 1;
            charArray[c1i] = charArray[c3i];
            charArray[c2i] = charArray[c4i];
            charArray[c3i] = c1;
            charArray[c4i] = c2;
        }
        return new String(charArray);
    }

原网址: 访问
创建于: 2024-08-16 17:09:00
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论