//字节数组转换为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进制字符串互转的更多相关文章

  1. Java-byte[]与16进制字符串互转

    转自: http://www.cnblogs.com/freeliver54/archive/2012/07/30/2615149.html Java中byte用二进制表示占用8位,而我们知道16进制 ...

  2. C# byte数组与16进制间的相互转换

      1.byte数组转16进制字符串 /// <summary> /// 将一个byte数组转换成16进制字符串 /// </summary> /// <param na ...

  3. java中把字节数组转换为16进制字符串

    把字符串数组转换为16进制字符串 import java.security.MessageDigest; public class StringUtil { public StringUtil() { ...

  4. C#//字节数组转16进制字符串

    //字节数组转16进制字符串 private static string byteToHexStr(byte[] bytes,int length) { string returnStr = &quo ...

  5. java byte数组与16进制间的相互转换

      java byte数组与16进制间的相互转换 CreationTime--2018年6月11日15点34分 Author:Marydon 1.准备工作 import java.util.Array ...

  6. java中byte[] 和16进制字符串互转

    //将byte[]转换为16进制字符串 public static String byte2hex(byte[] b) { StringBuilder hs = new StringBuilder() ...

  7. 字节数组(byte[])与16进制字符串转换

    /// <summary> /// 转换扩展类 /// </summary> public static class ConvertExtend { /// <summa ...

  8. 加密算法使用(二):使用MD5加密字符串(另:byte数组转16进制自动补零方法写法)

    public static void main(String args[]) throws NoSuchAlgorithmException { String s = new String(" ...

  9. python进制转化函数,10进制字符串互转,16进制字符串互转

    来了老弟,emmmmm,今天想到平时经常用到编码转化,把字符串转化为16进制绕过等等的,今天想着用python写个玩,查询了一些资料,看了些bolg 上面的两个函数是将二进制流转化为16进制,data ...

随机推荐

  1. 解决 web.xml is missing and <failOnMissingWebXml> is set to true 报错

    在学习maven模块化构建项目的时候遇到了如下报错信息: web.xml is missing and <failOnMissingWebXml> is set to true. 这时候需 ...

  2. python新生类和经典类简单说明

    经典类: #!/usr/bin/env python #*-* coding:utf-8 *-* class A(): def __init__(self): print 'my name is GF ...

  3. datetime24小时格式和12小时格式

    12:DateTime.Now.ToString("hh:mm:ss") 24:DateTime.Now.ToString("HH:mm:ss")

  4. .NET中低版本程序调用高版本DLL

    在.NET项目开发中,有时需要对旧的程序进行二次开发,但是有些DLL是高版本的,如果对旧程序升级高版本,则需要改动的地方比较多,在项目比较急,开发时间短的情况下,可以通过下面方法让低版本程序调用高版本 ...

  5. 《SQL Server 2008从入门到精通》--20180724

    目录 1.事务 1.1.事务的ACID属性 1.2.事务分类 1.2.1.系统提供的事务 1.2.2.用户自定义的事务 1.3.管理事务 1.3.1.SAVE TRANSACTION 1.3.2.@@ ...

  6. .net 操作MongoDB 基础

    1. 下载驱动,最好使用 NuGet 下载,直接搜索MongoDB: 2. 引用相关驱动 3. 部分测试代码,主要是针对MongoDB的GridFS 文件存储来用 using Mongo.Model; ...

  7. guider – 全系统Linux性能分析器

    Guider是一个免费且开源的,功能强大的全系统性能分析工具,主要以Python for Linux 操作系统编写. 它旨在衡量系统资源使用量并跟踪系统行为,从而使其可以有效分析系统性能问题或进行性能 ...

  8. 转:jQuery插件开发全解析

    jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...

  9. load file within a jar

    String examplejsPrefix = "example"; String examplejsSuffix = "js"; String exampl ...

  10. PHP类继承、接口继承关系概述

    PHP类继承: PHP类不支持多继承,也就是子类只能继承一个父类,但是支持多层次继承,比如: class frist{ public function __construct(){ echo &quo ...