无符号整数到BCD转换? [英] Unsigned Integer to BCD conversion?

查看:198
本文介绍了无符号整数到BCD转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用此表格将十进制转换为BCD:

I know you can use this table to convert decimal to BCD:

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

有这个转换的方程式,或者你只需​​要使用表?我想为这个转换写一些代码,但我不知道如何做它的数学。建议?

Is there a equation for this conversion or you have to just use the table? Im trying to write some code for this conversion but Im not sure how to do the math for it. Suggestions?

推荐答案

您知道二进制数字系统,不是吗?

特别看看本章

编辑:还要注意KFro的注释,数字的二进制ASCII表示的低半字节(= 4位)是在BCD中。这使得转换BCD < - > ASCII很容易,因为你只需要添加/删除前4位:

Also note KFro's comment that the lower nibble (= 4 bits) of the binary ASCII representation of numerals is in BCD. This makes conversions BCD <-> ASCII very easy as you just have to add/remove the leading 4 bits:


Number    ASCII Code
0         0011 0000
1         0011 0001
 ...
8         0011 1000
9         0011 1001

这篇关于无符号整数到BCD转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆