       Re: Number of Differing Digits & Another Problem (want to see different ways it can be done)

• To: mathgroup at smc.vnet.net
• Subject: [mg76330] Re: Number of Differing Digits & Another Problem (want to see different ways it can be done)
• From: dimitris <dimmechan at yahoo.com>
• Date: Sun, 20 May 2007 02:18:31 -0400 (EDT)
• References: <f2mf5b\$mbm\$1@smc.vnet.net>

```Various alternatives exist.
Below two are shown.
It is easy to make your user defined function from them.
I will just show the steps of the respective code.

1)

In:=
o1 = {IntegerDigits[20, 2, 5], IntegerDigits[31, 2, 5]}
Count[%, False]

Out=
{{1, 0, 1, 0, 0}, {1, 1, 1, 1, 1}}
Out=
{True, False, True, False, False}
Out=
3

2)

In:=
o2 = {IntegerDigits[126, 2, 7], IntegerDigits[357, 2, 7]}
Transpose[%]
DeleteCases[%, {a_, a_}]
Length[%]

Out=
{{1, 1, 1, 1, 1, 1, 0}, {1, 1, 0, 0, 1, 0, 1}}
Out=
{{1, 1}, {1, 1}, {1, 0}, {1, 0}, {1, 1}, {1, 0}, {0, 1}}
Out=
{{1, 0}, {1, 0}, {1, 0}, {0, 1}}
Out=
4

Dimitris

/  VenDiddy at gmail.com       :
> I just purchased a copy of Mathematica and I've been learning it for
> about a week now. You can expect that I will be posting a lot of
> questions. One thing I've noticed is that there are so many different
> ways to do the same thing!
>
> Here is a function I came up with that calculates how many binary
> digits two numbers differ in:
>
> BitDifferences[a_, b_, n_] :=
>  Count[Equal @@@
>    Thread[{IntegerDigits[a, 2, n], IntegerDigits[b, 2, n]}], True]
>
> For example 5 = 101 differs from 6 = 111 by one digit (the middle
> digit).
>
> I want to see how you would do it so I can broaden my Mathematica
> perspective.
>
> Thanks.

```

• Prev by Date: Re: Number of Differing Digits & Another Problem (want to see different ways it can be done)
• Next by Date: Re: Style sheets in 6.0
• Previous by thread: Re: Number of Differing Digits & Another Problem (want to see different ways it can be done)
• Next by thread:  LinearAlgebra`MatrixManipulation` LinearEquationsToMatrices [Where to find, missing in 6.0, what to replace with?]