将基数10算术算法转换为基数2算术算法 [英] converting base 10 arithmetic algorithms to base 2 arithmetic algorithms

查看:105
本文介绍了将基数10算术算法转换为基数2算术算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一堆我想重用的代码,因为我把它们保存在我的硬盘中,我不想浪费时间重新实现它们。所以我想知道我是否走在正确的轨道上。我得到了它的要点,但我想确保我以后不会遇到一些问题。



在我的所有算法中,我使用的是变量addToNextSlot和addToSlot。 addToNextSlot在除以10后在向量中放置一个数字,addToSlot从%10得到值。所以,如果我理解正确做基数2,我们只需要将%10和/ 10更改为%2和/ 2,对吧?当我将数字x与数字y相乘后得到这3行后,我得到值2时怎么样?我会在addToNextSlot中获得值3,所以这是我或者我根本无法重复使用我的代码而我必须考虑这一点而不是仅仅在这里和那里更改内容?



11111111

11111110

11111110

So I have a bunch of code I want to reuse, because I saved them up in my hard drive and I don't want to waste time re-implementing them. So I was wondering if I am on the right track. I got the gist of it, but I am trying to make sure I don't run into some problem later on.

In all of my algorithms, I use the variable addToNextSlot and addToSlot. addToNextSlot put a number in the vector after dividing by 10 and addToSlot get the value from %10. So if I understand correctly to do base 2, we just need to change %10 and /10 to %2 and /2, right? How about when I get the value 2 after I add up these 3 rows I get after multiplying a number x with a number y. I would get the value 3 in addToNextSlot, so it's me or I can't reuse my code at all and I have to think this through instead of just changing stuff here and there?

11111111
11111110
11111110

推荐答案

在纸上使用这些简单的计算根据不同系统中的符号定义自动验证您的计算:

http://en.wikipedia .org / wiki / Decimal_representation [ ^ ],

http://en.wikipedia.org/wiki/Binary_representation [ ^ ]。



问题太基础了,不能花太多时间,但这个将为您提供有用的练习。



-SA
Use those simple calculations on the piece of paper and validate your calculation automatically, working by definition of the notation in different systems:
http://en.wikipedia.org/wiki/Decimal_representation[^],
http://en.wikipedia.org/wiki/Binary_representation[^].

The problem is too basic to spend too much time on it, but this will serve a useful exercise for you.

—SA


这篇关于将基数10算术算法转换为基数2算术算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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