BYTE数组与16进制字符串互转
//字节数组转换为HEX 字符串
const string Byte2HexString(const unsigned char* input, const int datasize)
{
char output[datasize*];
for(int j = ; j < datasize; j++ )
{
unsigned char b = *(input+j);
snprintf( output+j * ,, "%02x",b);
}
return string(output) ;
}
/*
* 把16进制字符串转换成字节数组 @param hex @return
*/
unsigned char* HexString2Byte(string hex)
{
int len = (hex.length() / );
unsigned char* result = new unsigned char[len];
//const char* achar = hex.c_str();
for (int i = ; i < len; i++) {
int pos = i * ; QString lStr(hex[pos]);
int iLeft = lStr.toInt(NULL, ); QString rStr(hex[pos+]);
int iRight = rStr.toInt(NULL, ); int iNew = ( iLeft<< | iRight);
result[i] = (unsigned char) iNew;
}
return result;
}
调用演示:
BYTE face_feature[]; //16进制字符串转换为字节数组
unsigned char* pFeature = HexString2Byte(strFeature);
memcpy(face_feature, pFeature, strFeature.length()/); //字节数组转换为16进制字符串
string strFeature = Byte2HexString(face_feature,);
BYTE数组与16进制字符串互转的更多相关文章
- Java-byte[]与16进制字符串互转
转自: http://www.cnblogs.com/freeliver54/archive/2012/07/30/2615149.html Java中byte用二进制表示占用8位,而我们知道16进制 ...
- C# byte数组与16进制间的相互转换
1.byte数组转16进制字符串 /// <summary> /// 将一个byte数组转换成16进制字符串 /// </summary> /// <param na ...
- java中把字节数组转换为16进制字符串
把字符串数组转换为16进制字符串 import java.security.MessageDigest; public class StringUtil { public StringUtil() { ...
- C#//字节数组转16进制字符串
//字节数组转16进制字符串 private static string byteToHexStr(byte[] bytes,int length) { string returnStr = &quo ...
- java byte数组与16进制间的相互转换
java byte数组与16进制间的相互转换 CreationTime--2018年6月11日15点34分 Author:Marydon 1.准备工作 import java.util.Array ...
- java中byte[] 和16进制字符串互转
//将byte[]转换为16进制字符串 public static String byte2hex(byte[] b) { StringBuilder hs = new StringBuilder() ...
- 字节数组(byte[])与16进制字符串转换
/// <summary> /// 转换扩展类 /// </summary> public static class ConvertExtend { /// <summa ...
- 加密算法使用(二):使用MD5加密字符串(另:byte数组转16进制自动补零方法写法)
public static void main(String args[]) throws NoSuchAlgorithmException { String s = new String(" ...
- python进制转化函数,10进制字符串互转,16进制字符串互转
来了老弟,emmmmm,今天想到平时经常用到编码转化,把字符串转化为16进制绕过等等的,今天想着用python写个玩,查询了一些资料,看了些bolg 上面的两个函数是将二进制流转化为16进制,data ...
随机推荐
- Laravel安装教程
1.Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length() 报这个错是因为Apache/bin目录下 l ...
- 使用thumbnailator不按照比例,改变图片的大小
我们在平时的开发中,偶尔也会遇到图片处理的问题,比如图片的压缩,按比例改变图片的大小,不按比例改变图片的大小等等. 如果要自己去开发这样一套工具,我觉得大多数人都是做不到的,所以还是学会站在巨人的肩膀 ...
- axios的配置项
最近在学习vue,涉及到axios的ajax操作,记录一下相关Config,方便日后查阅 { // `url`是将用于请求的服务器URL url: '/user', // `method`是发出请求时 ...
- Visual Studio 2010详细安装过程
Visual Studio 2010在目前看来,应该是使用得比较多的一款微软的软件开发工具集合了,因为它具有以下优点:(1)启动速度快:在相同环境下,相比于Visual Studio 2015来说,2 ...
- Java计算大整数
import java.util.*; import java.math.*; //BigInteger类型在这个包里 public class Gcc_test { public static vo ...
- MySQL安全策略
0.导读 MySQL被运用于越来越多的业务中,在关键业务中对数据安全性的要求也更高,如何保证MySQL的数据安全? MySQL被运用于越来越多的业务中,在关键业务中对数据安全性的要求也更高,如何保证M ...
- 转:检查c#代码内存泄露工具-CLR Profiler工具使用
大家都知道.net有一套自己的内存(垃圾)回收机制,除非有一些数据(方法)长期占有内存不随着垃圾回收功能而释放内存,这样就造成了我们经常说的内存泄露.内存持续增长得不到释放等问题导致APS.NET网站 ...
- cat > file << EOF 与 cat > file << -
当我们在使用kickstart 的时候,会遇到写网卡配置文件的情况,这时候我们使用cat > file << EOF 命令等,可以从标准输入中接受输入并保存到 file 文件中. c ...
- gnome-shell 使用 notify-send 发送桌面消息
什么是notify-send? notify-send - a program to send desktop notifications 怎么使用? NAME notify-send - a pro ...
- Netty入门(九)空闲连接以及超时
检测空闲连接和超时是为了及时释放资源.常见的方法是发送消息来测试一个不活跃的连接,通常称为“心跳”. Netty 提供了几个 ChannelHandler 来实现此目的,如下: 下面是 IdleSta ...