[英]print BCD value with itoa
I need to print on screen a variable value that is encoded in BCD. 我需要在屏幕上打印以BCD编码的变量值。
Do you know whether is possible to print it on screen by using itoa
? 您知道是否可以使用itoa
在屏幕上打印它?
If that is possible, how to do that? 如果可能的话,该怎么做?
No, itoa
will not help. 不, itoa
将无济于事。 You want to look at the hexadecimal representation, so use hex
like in cout << hex << n << endl;
您想查看十六进制表示形式,因此请像在cout << hex << n << endl;
那样使用hex
cout << hex << n << endl;
Note: BCD codes the digits as 4-bit-sequences 0000 to 1001, which in hexadecimal are 0 to 9. So 23 as BCD would be 0010 0011
bitwise, or in fact as 8bit integer it would be 35, so converting this to a string will not be of much use. 注意:BCD将数字编码为4位序列0000至1001,十六进制为0至9。因此,由于BCD的23位将按位表示0010 0011
,或者实际上是8位整数,则应为35,因此将其转换为a字符串没有多大用处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.