实现进制转化伪代码
2021/11/6 23:40:37
本文主要是介绍实现进制转化伪代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
实现进制转化伪代码
伪代码
Write "Enter the new base" Read newBase Write "Enter the number to be converted" Read decimalNumber Set quotient to 1 WHILE (quotient is not zero) Set quotient to decimalNumber DIV newBase Set remainder to decimalNumber REM newBase Make the remainder the next digit to the left in the answer Set decimalNumber to quotient Write "The answer is " Write answer
用python编写的程序
# coding=utf-8 #实现进制转化伪代码 newBase = int( input('Enter the new base: ')) #输入想要转换的进制 decimaNumber = int(input('Enter the nember to be converted: ')) #转换的数字 quotient = 1 m = {10:'A',11:'B',12:'C',13:'D',14:'E',15:'F'} #用作16进制转换 b = [] while quotient != 0: quotient = decimaNumber // newBase remainder = decimaNumber % newBase if remainder > 9: remainder = m[remainder] b.append(remainder) decimaNumber = quotient b.reverse() for a in b: print(a,end="")
运行结果
(有二进制,八进制,十六进制)
这篇关于实现进制转化伪代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)