# [SOLVED] Need help...is there an equation to solve this easily?

• Dec 10th 2009, 10:28 AM
elleg
[SOLVED] Need help...is there an equation to solve this easily?
I'm new to this site, and I apologize if I've put this question in the wrong forum, but I really wasn't sure where it should go. This is not for a class.
...
So, right now I'm stuck with guess & check for this, unless someone knows a formula I can use.

I have the following equation:
A1+2B+C4+D8+E16+F32 = X

X is given. It is one value out of the set {1,2,3...63)

A,B,C,D,E,F can only be 0 or 1.

Is there a way to solve for A through F? There is only one right answer per value of X. For example, If X=1, then A=1 and B through F=0. Or, If X=3 then A=1, B=1, and C through F=0.

Having an equation to solve this will make this a lot simpler for me than creating a table of all 63 possibilities (64 if you include X=0).

Thanks!
• Dec 10th 2009, 10:56 AM
TheEmptySet
Quote:

Originally Posted by elleg
I'm new to this site, and I apologize if I've put this question in the wrong forum, but I really wasn't sure where it should go. This is not for a class.
...
So, right now I'm stuck with guess & check for this, unless someone knows a formula I can use.

I have the following equation:
A1+2B+C4+D8+E16+F32 = X

X is given. It is one value out of the set {1,2,3...63)

A,B,C,D,E,F can only be 0 or 1.

Is there a way to solve for A through F? There is only one right answer per value of X. For example, If X=1, then A=1 and B through F=0. Or, If X=3 then A=1, B=1, and C through F=0.

Having an equation to solve this will make this a lot simpler for me than creating a table of all 63 possibilities (64 if you include X=0).

Thanks!

If I am understanding this correctly

You want to know how many solutions there are to the eqution

$A+2B+4C+8D+16E+32F=X$ where $X=1...63$

This equation is just like binary numbers

$2^0A+2^2B+2^2C+2^3D+2^4E+2^5F=X$

The expression of numbers is Binary is unique so there is only one solution for each X.

I hope this helps
• Dec 10th 2009, 11:09 AM
elleg
You're right. I was thinking of A through F as booleans, but rather than true-false they are 1 or 0, so yes, binary numbers.

My problem is that I'm not sure how to solve that equation. It's been years since I had to deal with binary numbers. I'm currently googling binary/boolean equations, binary/boolean algebra, etc. to see if I can find an answer.
• Dec 10th 2009, 11:38 AM
emakarov
Any number from 0..63, when it is converted into binary, can be written using 6 binary digits. In fact, there is a bijection between the set X={0,...,63} and the set Y={(A,B,C,D,E,F) | each of A,...,F is 0 or 1}. This means that there are two mutually inverse functions f: X -> Y and g: Y -> X. The function g(A,B,C,D,E,F) is in fact given by the formula A+2B+4C+8D+16E+32F. The function f is the one that converts decimal into binary. So, given n in X, to find the solution to the equation A+2B+4C+8D+16E+32F = n you calculate f(n). This is the only solution because f and g constitute a 1-1 correspondence.

I may have described it a little too heavily; the intuitive idea is simpler than this.
• Dec 10th 2009, 11:55 AM
elleg
Awesome...that just clicked for me.

So, basically, my variables A,B,C,D,E,F actually make up the positions of the base 2 version of my base 10 variable X.

Thus
If X=1 Then:
FEDCBA
000001
(A=1, All others=0)

If X=2 Then:
FEDCBA
000010
(B=1, All others=0)

If X=3 Then:
FEDCBA
000011
(A=1,B=1, All others=0)

So, all I have to do is convert X to base 2, and then use each position of the base 2 number.

Thanks!