关于printf函数打印二进制问题!

C_520 2006-05-12 02:36:52
printf函数有一个能直接打印2进制的格式吧,那位大哥知道告诉告诉我,谢谢了

#include <stdio.h>

int main(void)
{
int i = 31;

printf("i = %b\n", i);

return 0;
}
...全文
14439 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jixingzhong 2006-05-12
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>


void main()
{
int i = 31;
char s[10];

itoa(i, s, 2); //转换成字符串,进制基数为2
printf("%s",s); //输出
getch();
}
jixingzhong 2006-05-12
  • 打赏
  • 举报
回复
不能直接打印 2进制
需要处理一下才可以 .....
winter_plusplus 2006-05-12
  • 打赏
  • 举报
回复
Size Prefixes for scanf and wscanf Format-Type Specifiers
To Specify Use Prefix With Type Specifier
double l e, E, f, g, or G
long double (same as double) L e, E, f, g, or G
long int l d, i, o, x, or X
long unsigned int l u
short int h d, i, o, x, or X
short unsigned int h u
__int64 I64 d, i, o, u, x, or X
Single-byte character with scanf h c or C
Single-byte character with wscanf h c or C
Wide character with scanf l c or C
Wide character with wscanf l c, or C
Single-byte – character string with scanf h s or S
Single-byte – character string with wscanf h s or S
Wide-character string with scanf l s or S
Wide-character string with wscanf l s or S


Following are examples of the use of h and l with scanf functions and wscanf functions:

scanf( "%ls", &x ); // Read a wide-character string
wscanf( "%lC", &x ); // Read a single-byte character

Rocyee 2006-05-12
  • 打赏
  • 举报
回复
目前printf支持以下格式:
%c 单个字符
%d 十进制整数
%f 十进制浮点数
%o 八进制数
%s 字符串
%u 无符号十进制数
%x 十六进制数
%% 输出百分号%
Rocyee 2006-05-12
  • 打赏
  • 举报
回复
%x 十六进制

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧