单片机中printf重定向输出u8u16的%输出格式介绍

本文转载为

本文为CSDN博主「悟空明镜」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wukongmingjing/article/details/81709429

u8,u16等在C语言中的定义为

typedef signed char s8;  
typedef unsigned char u8;  
  
typedef signed short s16;  
typedef unsigned short u16;  
  
typedef signed int s32;  
typedef unsigned int u32;  
  
typedef signed long long s64;  
typedef unsigned long long u64;

与体系结构相关的,定义在include/linux/type.h文件中:

/* bsd */
typedef unsigned char		u_char;
typedef unsigned short		u_short;
typedef unsigned int		u_int;
typedef unsigned long		u_long;

/* sysv */
typedef unsigned char		unchar;
typedef unsigned short		ushort;
typedef unsigned int		uint;
typedef unsigned long		ulong;

#ifndef __BIT_TYPES_DEFINED__
#define __BIT_TYPES_DEFINED__

typedef		__u8		u_int8_t;
typedef		__s8		int8_t;
typedef		__u16		u_int16_t;
typedef		__s16		int16_t;
typedef		__u32		u_int32_t;
typedef		__s32		int32_t;

#endif /* !(__BIT_TYPES_DEFINED__) */

typedef		__u8		uint8_t;
typedef		__u16		uint16_t;
typedef		__u32		uint32_t;

#if defined(__GNUC__)
typedef		__u64		uint64_t;
typedef		__u64		u_int64_t;
typedef		__s64		int64_t;
————————————————
版权声明:本文为CSDN博主「悟空明镜」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wukongmingjing/article/details/81709429

具体的打印格式为

数据类型打印格式
u8%d
s8%d
u16%d or %hu
s16%d or %hd
u32%u
s32%d
u64%llu
s64%lld
int%d
unsigned int%u
short int%d or %hd
long%ld
unsigned long%lu
long long%lld
unsigned long long%llu
char%c
char *%s
bool (#define stdbool.h)%d
unsigned int/int------>十六进制%0x
unsigned long/long---->十六进制%0lx
long long/unsigned long long ----->十六进制%0llx
unsigned int/int------>八进制%0o
unsigned long/long---->八进制%0lo
long long/unsigned long long ----->八进制%0llo
float%f
double%f or %lf
科学技术类型(必须转化为double类型)%e
限制输出字段宽度%x.yf (x:整数长度,y:小数点长度)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值