uint16_t转换成char_16bit转8bit
转换成 char uint16
2023-06-13 09:13:44 时间
大家好,又见面了,我是你们的朋友全栈君。
简单来说,uint8_t / uint16_t / uint32_t /uint64_t这些数据类型都只是别名而来,具体如下:
一、C语言数据基本类型
在C语言中有6种基本数据类型:short、int、long、float、double、char
1)整型:short int、int、long int
2)浮点型:float、double
3)字符类型:char
二、分析uint8_t\uint_16_t\uint32_t\uint64_t
1、数据来源:这些数据类型中都带有_t, _t 表示这些数据类型是通过typedef定义的,而不是新的数据类型。也就是说,它们其实是我们已知的类型的别名。
2、typedef:typedef用来定义关键字或标识符的别名
3、使用原因:方便代码的维护。比如,在C中没有bool型,于是在一个软件中,一个程序员使用int,一个程序员使用short,会比较混乱,最好用一个typedef来定义一个统一的bool,每个程序员都可以用这个别名的bool。
不同的平台会有不同的字长,所以利用预编译和typedef可以方便的维护代码。
typedef unsigned char uint8_t;//将uint8_t别名为无符号字符型
4、定义:在C99标准中定义了这些数据类型,具体定义在:stdint.h中
定义类型如下:
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed __INT64 int64_t;
/* exact-width unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __INT64 uint64_t;
/* 7.18.1.2 */
/* smallest type of at least n bits */
/* minimum-width signed integer types */
typedef signed char int_least8_t;
typedef signed short int int_least16_t;
typedef signed int int_least32_t;
typedef signed __INT64 int_least64_t;
/* minimum-width unsigned integer types */
typedef unsigned char uint_least8_t;
typedef unsigned short int uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned __INT64 uint_least64_t;
/* 7.18.1.3 */
/* fastest minimum-width signed integer types */
typedef signed int int_fast8_t;
typedef signed int int_fast16_t;
typedef signed int int_fast32_t;
typedef signed __INT64 int_fast64_t;
/* fastest minimum-width unsigned integer types */
typedef unsigned int uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned __INT64 uint_fast64_t;
/* 7.18.1.4 integer types capable of holding object pointers */
#if __sizeof_ptr == 8
typedef signed __INT64 intptr_t;
typedef unsigned __INT64 uintptr_t;
#else
typedef signed int intptr_t;
typedef unsigned int uintptr_t;
#endif
/* 7.18.1.5 greatest-width integer types */
typedef signed __LONGLONG intmax_t;
typedef unsigned __LONGLONG uintmax_t;
5、格式化输出:
1)uint16_t %hu
2)uint32_t %u
3)uint64_t %llu
6、uint8_t类型的输出:
typedef unsigned char uint8_t;//将uint8_t别名为无符号字符型
uint8_t buf = 65;
printf("buf = %d",buf);//错误
printf("buf = %c",buf);//正确,打印出字符的ASCII码
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/196239.html原文链接:https://javaforall.cn
相关文章
- String转JSONArray,遍历JSONArray,Array数组转换成JSON字符串
- 【说站】JSON字符串如何转换成Python?
- java整型转换成字符串_java整型转换成字符串
- html可以转换成word_html显示word文档
- 将char转换成int_c语言中int转char
- c语言中char转换成string_字符数字转为int型
- EMNLP 2022 | 复杂标签空间下的Prompt调优( 将关系分类转换成填充问题)
- 手把手教你如何将SOCKS5代理转换成HTTP代理?
- CSS 如何设置背景透明,并使用 PHP 将十六进制的颜色值转换成 RGBA 格式
- Python使用np.c_和np.r_实现数组转换成矩阵详解编程语言
- Python 2to3:自动将Python 2.x代码转换成Python3.x代码
- MySQL中将日期转换成字符串(mysql日期转换字符串)
- MySQL中的CHAR类型:实用性与可扩展性(mysql的char)
- MySQL数据类型技巧:从String转换到Int(mysql转换成int)
- MySQL实现秒数快速转换为时间格式(mysql秒转换成时间)
- MSSQL日期格式转换技巧(mssql转换成日期格式)
- MySQL中的Char长度限制(mysql中char长度)
- 如何在MySQL中使用CHAR字段来实现自增功能(mysql中char自增)
- MySQL中CHAR方法详解及实例演示(mysql中char方法)
- MySQL中的CHAR字段类型介绍(char在mysql)
- 中Oracle中Char类型的应用及其优势(char在oracle)
- asp.net(vb)实现金额转换成大写的函数
- asp.net如何将DataSet转换成josn并输出
- 将数字转换成大写的人民币表达式的js函数