linux下10进制16进制互转函数
来源:互联网 发布:淘宝联盟网 编辑:程序博客网 时间:2024/05/24 02:33
转自:http://blog.chinaunix.net/uid-26520343-id-3211625.html
*
* 17-May-2012Auther.Zhang 0.0 Version
* Copyright & the right of find interpretation auther
* synopsis:特殊的进制转换
*
*/
#include <stdio.h>
#include <stdlib.h>
typedef unsigned charUchar; //1Byte
typedef unsigned short intUint; //2Byte
typedef unsigned longUlong; //4Byte
/****************************************************************
函数说明 :十进制转十六进制,字符转换不涉及数值大小,特殊用途
入口参数 :需要转换的十进制数
返回类型 :转换完成的十六进制数
初始时间 :2012-5-17Lebaishi
修改记录 :
用途功能 :将十进制直接转换为十六进制,例如12直接转为0x12等
****************************************************************/
char Dec2hex(int dec_data)
{
Uchar *s=malloc(10);
Ulong bcd_data;
sprintf(s,"%d",dec_data); //dec_data=12,s="12"
sscanf(s,"%x",&bcd_data);
free(s);
return bcd_data;
}
/****************************************************************
函数说明 :十六进制转十进制,字符转换不涉及数值大小,特殊用途
入口参数 :需要转换的十六进制数
返回类型 :转换完成的十进制数
初始时间 :2012-5-17Lebaishi
修改记录 :
用途功能 :将十六进制直接转换为十进制,例如0x12直接转为12等
****************************************************************/
char hex2Dec(Uchar bcd_data)
{
Uchar *s=malloc(10);
Ulong dec_data;
sprintf(s,"%x",bcd_data);
sscanf(s,"%d",&dec_data);
free(s);
return dec_data;
}
/***************** 主函数 ******************/
int main()
{
char hex_dec=0;
char dec_hex=0;
hex_dec = Dec2hex(12);
printf("Dec2hex(12):\n");
printf("come in:12 Dec output:%d\n",hex_dec);
printf("come in:12 Dec output:%#x\n",hex_dec);
dec_hex = hex2Dec(0x12);
printf("hex2Dec(0x12):\n");
printf("come in:0x12 output:%d\n",dec_hex);
printf("come in:0x12 output:%#x\n,dec_hex");
return 1;
}
0 0
- linux下10进制16进制互转函数
- linux下mmap()函数
- linux下mmap()函数
- Linux下bzero函数
- linux下system函数
- linux下system函数
- linux下system函数
- Linux下mkdir函数
- linux下HMAC函数
- linux下listen函数
- Linux下fork()函数
- Linux下pthread_once()函数
- linux下hook函数
- linux下signal函数
- linux下system函数
- linux 下常用函数
- linux下select函数
- linux下remove函数
- 欢迎进群大家以后一起交流 CSharp、.Net技术交流群 242497960
- 全球速卖通教你怎么样分析数据纵横-行业情报选
- 数据结构(c++版) 第三章栈和队列
- 表解锁
- 文字就像是一扇虚掩的门
- linux下10进制16进制互转函数
- 关于一个简单的复选框的定制
- c/c++ 多重继承下的二义性解决方法
- android WheelView时间选择器
- AppCompat V21:将 Materia Design 兼容到5.0之前的设备
- WinCE Security --- 文件及证书签名与验证
- 全球速卖通教你怎么样分析数据纵横-行业情报选
- (转)NSString / NSMutableString 字符串处理,常用代码 (实例)
- 租用游艇问题