BYTE数组与16进制字符串互转
2024-10-19 04:29:41
//字节数组转换为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,);
最新文章
- 在Thinkphp中使用AJAX实现无刷新分页
- 阿里云centos安装svn和submin
- JavaScript基础------入门基础
- DbHelperSQL 判断数据库表结构公用方法
- 微信热修复tinker及tinker server快速接入
- 配置 VS 2015 开发跨平台手机应用
- 在WPF中使用ArcGIS Engine
- chrome浏览器访问google插件
- Libgdx 1.6.1发布,跨平台游戏开发框架
- 【进阶1-3期】JavaScript深入之内存空间详细图解(转)
- 如何使用HttpClient包实现JAVA发起HTTP请求?
- Codeforces Round #505 (Div 1 + Div 2 Combined) Solution
- Django-website 程序案例系列-5 模态对话框实现提交数据
- HTML格式化标签
- centos7部署openvpn-2.4.6
- [UE4]name slot一个种应用技巧
- MySQL数据行溢出的深入理解
- 关于安装VS2010过程中的错误
- C#treeView控件单击事件选中节点滞后问题解决方法
- [转载]meclipse中project facet问题
热门文章
- DataContract和DataMember的作用
- 使用 PowerShell 管理 Azure 磁盘
- SQL Server全文搜索(转载)
- If TransactionScope will close database connections
- SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析 (转载)
- C#实现复制文件夹中文件到另一个文件夹的方法
- cut切割,简单的取列
- 乘风破浪:LeetCode真题_033_Search in Rotated Sorted Array
- 【2017下集美大学软工1412班_助教博客】团队编程2-需求分析&;原型设计团队成绩公示
- 树莓派3B+ wifi 5G连接