六角带codeD字符串字节数组 [英] Hex-encoded String to Byte Array

查看:135
本文介绍了六角带codeD字符串字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String str = "9B7D2C34A366BF890C730641E6CECF6F";

我想 STR 转换成字节数组,但 str.getBytes()返回32个字节,而不是16

I want to convert str into byte array, but str.getBytes() returns 32 bytes instead of 16.

推荐答案

我想提问时后的字符串再一个十六进制值presentation转换为一个字节数组重新presenting的十六进制值。

I think what the questioner is after is converting the string representation of a hexadecimal value to a byte array representing that hexadecimal value.

在阿帕奇commons- codeC具有该<一类href=\"http://commons.apache.org/proper/commons-$c$cc/apidocs/org/apache/commons/$c$cc/binary/Hex.html\">Hex.

The apache commons-codec has a class for that, Hex.

String s = "9B7D2C34A366BF890C730641E6CECF6F";    
byte[] bytes = Hex.decodeHex(s.toCharArray());

这篇关于六角带codeD字符串字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆