用于将二进制转换为十进制的伪代码 [英] Pseudocode for converting binary to decimal

查看:1296
本文介绍了用于将二进制转换为十进制的伪代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个有效的伪代码,用于将任何二进制代码转换为等效的十进制代码

解决方案

这并不复杂:你只需要做什么使用模数和除运算符直到没有数字:



1)将 inp 设置为二进制数。

2)将数字设置为 inp 模数10.输出数字

3)将 inp 设置为 inp 划分by 10

4)如果 inp 不为零,请从(2)


$ b重复$ b唯一的复杂因素是这会生成错误顺序的数字:最不重要的数字。所以你需要让你的输出数字处理它,并可能以相反的顺序存储它们以便最后输出。你究竟是怎么做的并不复杂,但我不知道你的课程有多远,所以我不会暗示任何事情 - 你可能从讲座中得知这是作业从

Please i needed to a working pseudo code for converting any binary code to its equivalent decimal representation

解决方案

It''s not complex: all you need to do is use the modulus and divide operators until there is no number left:

1) Set inp to binary number.
2) Set digit to inp modulus 10. Output digit
3) Set inp to inp divided by 10
4) If inp is not zero, repeat from (2)

The only complication is that this generates the digits in the wrong order: least significant first. So you will need to make your "Output Digit" cope with that, and probably store them in reverse order for output at the end. Exactly how you do that isn''t complex, but I don''t know how far you have got in your course, so I won''t suggest anything - you have probably got an idea from the lecture that this was the homework from.


这篇关于用于将二进制转换为十进制的伪代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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