博客
关于我
C语言16进制字符串转为16进制
阅读量:496 次
发布时间:2019-03-07

本文共 998 字,大约阅读时间需要 3 分钟。

#include 
#include
#include
typedef unsigned char BOOL_T; typedef unsigned char U8_T; typedef signed char S8_T; typedef unsigned short U16_T; typedef signed short S16_T; typedef unsigned int U32_T; typedef signed int S32_T;typedef unsigned __int64 U64_T;typedef signed __int64 S64_T; typedef float F32_T; typedef double F64_T; typedef char * STR_T;//16进制字符串转为16进制void StrToHex(U8_T* pbDest, U8_T* pbSrc, U8_T nLen){ U8_T h1,h2; U8_T s1,s2; U8_T i; for (i = 0; i < nLen; i++) { h1 = pbSrc[2*i]; h2 = pbSrc[2*i+1]; s1 = toupper(h1) - 0x30; if (s1 > 9) s1 -= 7; s2 = toupper(h2) - 0x30; if (s2 > 9) s2 -= 7; pbDest[i] = s1*16 + s2; }}int main(){ int i; U8_T tmp[12] = "010203040506"; U8_T out[6] = {0}; memset(out, 0 ,8); //16进制字符串转为16进制 StrToHex(out, tmp, 6); for(i = 0; i < sizeof(out); i++) { printf("out[%d] : %x \n", i, out[i]); } return 0; }

运行结果:

在这里插入图片描述

转载地址:http://dopcz.baihongyu.com/

你可能感兴趣的文章
Nacos配置Mysql数据库
查看>>
Nacos配置中心中配置文件的创建、微服务读取nacos配置中心
查看>>
Nacos配置中心集群原理及源码分析
查看>>
nacos配置在代码中如何引用
查看>>
nacos配置新增不成功
查看>>
nacos配置自动刷新源码解析
查看>>
nacos集成分布式事务插件Seata的序列化问题,实际上是Seata本身存在bug!!
查看>>
Nacos集群搭建
查看>>
nacos集群搭建
查看>>
nacos集群网络分区对的影响和运维方式
查看>>
nacos集群节点故障对应用的影响以及应急方法
查看>>
nacos集群配置详解
查看>>
nagios 实时监控 iptables 状态
查看>>
nagios+cacti整合
查看>>
Nagios介绍
查看>>
nagios利用NSCient监控远程window主机
查看>>
nagios安装文档
查看>>
nagios服务端安装
查看>>
Nagios自定义监控脚本
查看>>
name_save matlab
查看>>