Re: Number of Differing Digits & Another Problem (want to see different ways it can be done)
- To: mathgroup at smc.vnet.net
- Subject: [mg76328] Re: [mg76310] Number of Differing Digits & Another Problem (want to see different ways it can be done)
- From: "Patrick Scheibe" <mai99dnn at studserv.uni-leipzig.de>
- Date: Sun, 20 May 2007 02:17:29 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <200705190845.EAA21281@smc.vnet.net>
Hi,
I would say that the binary form of 6 is more like
BaseForm[6, 2]=110
and so 5 and 6 differ in two digits.
BitDifference[a_, b_] := Plus @@ IntegerDigits[BitXor[a, b], 2]
Cheers
Patrick
Am 19.05.2007, 10:45 Uhr, schrieb <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.
>
--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
- References:
- Number of Differing Digits & Another Problem (want to see different ways it can be done)
- From: VenDiddy@gmail.com
- Number of Differing Digits & Another Problem (want to see different ways it can be done)