方法一:

unsigned char* hexstr_to_char(const char* hexstr)
{
size_t len = strlen(hexstr);
IF_ASSERT(len % != )
return NULL;
size_t final_len = len / ;
unsigned char* chrs = (unsigned char*)malloc((final_len+) * sizeof(*chrs));
for (size_t i=, j=; j<final_len; i+=, j++)
chrs[j] = (hexstr[i] % + ) % * + (hexstr[i+] % + ) % ;
chrs[final_len] = '\0';
return chrs;
}

方法二:

int byteArrayToHexString(uint8_t *byte_array, int byte_array_len,
char *hexstr, int hexstr_len)
{
int off = ;
int i; for (i = ; i < byte_array_len; i ++) {
off += snprintf(hexstr + off, hexstr_len - off,
"%02x", byte_array[i]);
} hexstr[off] = '\0'; return off;
}

来源:

十六进制字符串转byte (无符号字符串);的更多相关文章

  1. strtoul (将字符串转换成无符号长整型数)

    strtoul strtoul (将字符串转换成无符号长整型数) 相关函数 atof,atoi,atol,strtod,strtol 表头文件 #include<stdlib.h> 定义函 ...

  2. java有符号无符号的转换

    数据处理中常常遇到基本数据类型的操作,java都是有符号的数据,而与下位机通信中常常遇到无符号的比如uint8, uint16,uint32等等 1.为了完成这个功能还专门采用ByteBuffer的方 ...

  3. Golang十六进制字符串和byte数组互转

    Golang十六进制字符串和byte数组互转 需求 Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包 实现Demo package main i ...

  4. python3字符串的方法及注释/ 字符串格式化符号含义及格式化符号含义

     capitalize()   把字符串的第一个字符改为大写   casefold()   把整个字符串的所有字符改为小写   center(width)   将字符串居中,并使用空格填充至长度wid ...

  5. java 无符号byte转换

    java中的byte类型是有符号的,值得范围是-128-127 做网络通讯时,接收过来的数据往往都是无符号的byte,值得范围是0-255 因此直接转换时,存储到java显示的值就会有问题 int o ...

  6. 字符串与byte数组转换

    string weclome=""; byte[] data = new byte[1024]; //字符串转byte数组 data = Encoding.ASCII.GetByt ...

  7. php byte数组与字符串转换类

    <?php /** * byte数组与字符串转化类 * @author ZT */ class Bytes { /** * 转换一个string字符串为byte数组 * @param $str ...

  8. C#中字符串与byte[]相互转换

    字符串转换为byte[] 给定一个string,转换为byte[],有以下几种方法. 方法1: static byte[] GetBytes(string str) { byte[] bytes = ...

  9. 获取java byte的无符号数值

    byte a = (byte)234; System.out.println(a); 上面的代码,结果是-22,因为java中byte是有符号的,byte范围是-128~127. 如果想输出234,该 ...

随机推荐

  1. yii2.0 ActiveRecord 查询汇总

    User::find()->all(); 此方法返回所有数据: User::findOne($id); 此方法返回 主键 id=1 的一条数据(举个例子): User::find()->w ...

  2. 源代码管理工具GIT

    01.GIT简介 svn是集中式的源代码管理工具,必须联网才能操作 git是分布式的. 有两中:一个是本地代码仓库,一个是远程代码仓库 分布式源代码管理工具 02.GIT - 本地代码仓库使用流程 1 ...

  3. BZOJ_2947_[Poi2000]促销_堆

    BZOJ_2947_[Poi2000]促销_堆 Description Bytelandish连锁超市委托你编写一个程序来模拟一项即将施行的促销活动,该活动的规则如下: ●想要参与的顾客,只需把他的个 ...

  4. bzoj 1127 KUP —— 最大子矩形+答案构造

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1127 首先,把权值 > 2*k 的点作为“坏点”,然后在图中用悬线法找权值最大的子矩形 ...

  5. robotframework执行用例时,报错selenium.common.exceptions.WebDriverException: Message: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinl

    在用robotframework编写移动端测试用例(用chrome浏览器模拟手机浏览器),执行用例时, 报错selenium.common.exceptions.WebDriverException: ...

  6. 1.jeesite环境搭建

    安装部署 1. 运行Maven目录下的settings.bat文件,用来设置maven仓库路径,并按提示操作(设置PATH系统变量.配置Eclipse). 2. 执行jeesite/bin/eclip ...

  7. UNIX 环境模拟工具Cygwin安装及使用图文教程

    对于 UNIX 本身,也有各种称呼.IBM® 大型机用户说各种带字母 "z" 的行话,比如 IBM z/OS® 和 System z9 Virtual Machine (z/VM) ...

  8. JS处理时间相关

    <script>var d=new Date(); alert(d);alert(d.getMonth());alert(d.getHours());alert(d.getYear()); ...

  9. tar 报错gzip: stdin: not in gzip format(转载)

    转自:http://blog.sina.com.cn/s/blog_6f2274fb0100z026.html 今天在linux下 用tar -zxf xxx.tar.bz2 然后就报这个错. gzi ...

  10. 51nod 1122 机器人走方格 V4 【矩阵快速幂】

    首先建立矩阵,给每个格子编号,然后在4*4的格子中把能一步走到的格子置为1,然后乘n次即可,这里要用到矩阵快速幂 #include<iostream> #include<cstdio ...