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.

See more:

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

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

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

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.

Permalink

Share this answer

v2

Comments

CPallini
4-Mar-14 4:19am

5.

Sergey Alexandrovich Kryukov
4-Mar-14 10:07am

Thank you, Carlo.

—SA

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900