Binary to Decimal Guide

advertisement
Binary to Decimal Conversion
When we solve a problem we interpret a problem in different ways. While one
approach is more efficient than others there is no wrong approach. If you have solved a
problem but your solution is not correct it does not mean that all your effort is worthless.
Most of your solutions will always work with a minor “fix”.
Also remember that after you have tried and failed many times from looking at
one point there are many different points to look at a problem from. You should always
look at problems from different perspectives.
In this particular problem we can also take a different approach. Let’s see how we
can bring this problem to some simple steps. First let’s find out what we are going to
accomplish here. We have to convert numbers from binary form to decimal form. Let’s
say we want to convert 1011 from its Binary form to Decimal form. We can accomplish
this task in the following manner:
Row1
Row2
C1
24
16
Row3
0
C2
3
2
8
C3
22
4
1
0
C4
21
2
C5
20
1
1
1
8*1+4*0+2*1+1*1 = 11.
So if we look at the table above, we see that we are increasing the power of two
by one and multiplying the result by 1 or 0. We are also adding the trailing products.
Now, to program this in RIS we can take one simple approach. We know that at
anytime the decimal equivalent of a binary number is the summation of [Row2 * Binary
number]. Let’s say you are on C3 and want to find out what is 011 (from Row3) in
decimal form. You can just get the summation of [Row2 * Binary number] up to C3. It is
3 in Decimal (4*0+2*1+1*1 = 3). We see that if we keep an aggregate summation at
anytime we can find the decimal equivalent of a binary number. So if we display that
aggregated sum we basically display the decimal equivalent of a binary number. So when
we have two sensors (Sensor1 indicating 1 and Sensor2 indicating 0) at anytime if
Sensor1 is pressed we can increase the power of two and get the product and update the
aggregated sum and display it. If Sensor2 is pressed we can increase the power of two but
we don’t have to update the aggregate sum.
The above method is one of the ways we can solve this problem. You may have a
different method in your mind which could be as efficient as any other solution.
Now, if we analyze the above solving strategy we see that first we wrote down the
problem in our own form to understand each detail of it. Once we had all the details
worked out we decided to transform our analysis to codes. You should always make sure
that you interpret a problem correctly and write a rough solution in your own way. Don’t
think about coding yet. Just work on each step toward getting a solution in your own way.
Eliminate unnecessary information and concentrate on the necessary ones. Then connect
the necessary information to get the ultimate solution. After you think that your solutions
is workable then code it.
Download