uint16_t转换成char_16bit转8bit

uint16_t转换成char_16bit转8bit简单来说,uint8_t/uint16_t/uint32_t/uint64_t这些数据类型都只是别名而来,具体如下:一、C语言数据基本类型在C语言中有6种基本数据类型:short、int、long、float、double、char1)整型:shortint、int、longint2)浮点型:float、double3)字符类型:char二、分析uint8_…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

简单来说,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中

uint16_t转换成char_16bit转8bit

定义类型如下:

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.net/196239.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • DB9串口和RJ45串口

    大家好,又见面了,我是你们的朋友全栈君。

    2022年4月8日
    56
  • navicat15激活码-激活码分享

    (navicat15激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~M…

    2022年3月21日
    127
  • kotlin和java互转

    kotlin和java互转其实就是互转 以下基于 IDEA 或 AndroidStudi 转 Kotlin 打开要转的文件方法 1Ctrl Shift Alt K 方法 2Code ConvertJavaF 转 JavaTools gt Kotlin gt ShowKotlinBy

    2025年6月18日
    0
  • 查看已安装PERL的模块

    查看已安装PERL的模块

    2021年8月4日
    61
  • python encode和decode的区别_encode和decode的区别

    python encode和decode的区别_encode和decode的区别字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码。decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode(‘gb2312’),表示将gb2312编码的字符串str1转换成unicode编码。e…

    2022年10月7日
    0
  • Apache 安装与配置「建议收藏」

    Apache 安装与配置「建议收藏」一、下载http://httpd.apache.org/download.cgi二、安装安装过程很简单,因为是压缩包,所以,先将其解压包中的Apache24解压到合适的位置,我将其解压到了D盘soft目录。配置找到D:\soft\Apache24\conf\httpd.conf文件,用记事本打开,找到DefineSRVROOT…

    2022年9月21日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号