格式二进制输出 [英] formatting binary output
问题描述
我的程序将小数转换为二进制,十六进制等。
二进制数的输出形式为0000 0000,所有数字从0
到300有没有人有任何建议如何获得每4位之间的空间
?
提前谢谢。
My program converts decimals to binary, hex etc. The output of the
binary numbers are to be in the form 0000 0000 for all numbers from 0
to 300. Does anyone have any suggestions as how to get the space
between each 4 bits?
Thanks in advance.
推荐答案
2007年9月12日星期三18:44:00 -0700, zg *** ***@gmail.com 写在
comp.lang.c ++:
On Wed, 12 Sep 2007 18:44:00 -0700, zg******@gmail.com wrote in
comp.lang.c++:
我的程序将小数转换为二进制,对于从0
到300的所有数字,
二进制数的输出形式为0000 0000.有没有人有任何建议如何获得空间
每4位之间
?
提前谢谢。
My program converts decimals to binary, hex etc. The output of the
binary numbers are to be in the form 0000 0000 for all numbers from 0
to 300. Does anyone have any suggestions as how to get the space
between each 4 bits?
Thanks in advance.
您的要求无法满足。二进制值300是
100101100,空格是1 0010 1100.没有办法将二进制300的值作为文本使用少于9的
角色。
-
杰克克莱恩
主页: http://JK-Technology.Com
常见问题解答
comp.lang.c http://c-faq.com/
comp.lang .c ++ http://www.parashift.com/c++-faq-lite /
alt.comp.lang.learn.c-c ++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Your requirement is impossible to meet. The value 300 in binary is
100101100, with spaces it is 1 0010 1100. There is no way to present
the value of 300 in binary as text using fewer than 9 characters.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
请原谅我。只有值0到255,255是1111 1111?
Pardon me.What about only the values 0 to 255,with 255 being 1111 1111?
In文章< 11 ********************** @ g4g2000 hsf.googlegroups。 com>,
zg******@gmail.com 说......
In article <11**********************@g4g2000hsf.googlegroups. com>,
zg******@gmail.com says...
请原谅我。只有0到255的值,255是1111 1111?
Pardon me.What about only the values 0 to 255,with 255 being 1111 1111?
显而易见的方法是为每个可能的nybble值创建一个数组(或向量)或字符串,一个
(16可能的价值观)。使用类型
四位作为索引,打印出所选字符串,打印一个空格,然后
打印出用最后四位索引的字符串。
-
后来,
杰瑞。
宇宙是它的一个虚构自己的想象力。
The obvious way would be to create an array (or vector) or strings, one
for each possible value of a nybble (16 possible values). Use the type
four bits as an index, print out the chosen string, print a space, then
print out the string indexed with the bottom four bits.
--
Later,
Jerry.
The universe is a figment of its own imagination.
这篇关于格式二进制输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!