为什么我们不能以十进制、八进制、十六进制等二进制形式打印值? [英] why we can't print the value in binary form like decimal, octal, hexadecimal form?
问题描述
为什么我们不能像在 C 编程中那样以二进制形式打印数字.
Why can't we print a number in binary like other in C programming.
示例:
int a=9;
printf("%b",a);
就像我们可以以其他形式打印一样:
like we can print in other form:
- 八进制
printf("%o",a);
- 十进制
printf("%d",a);
- 十六进制
printf("%x",a);
推荐答案
这与 C 语言本身无关.只是,C 标准并没有为 printf()
和 family 指定格式说明符来默认生成二进制表示输出.
This has nothing to do with C language, per se. It's just that, the C standard does not specify a format specifier for printf()
and family to produce a binary representation output, by default.
您始终可以推出自己的功能来完成工作.有一些版本的 C 库选择提供一个格式说明符(以及一个整数后缀)来表示二进制表示,但同样,这既不是官方标准也没有强制规定.
You can always roll out your own function to get the job done. There are some versions of C library which chose to provide a format specifier (and an integer suffix also) to denote binary representation but once again, that is neither mandated not regulated by the official standard.
这篇关于为什么我们不能以十进制、八进制、十六进制等二进制形式打印值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!