MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Number of Differing Digits & Another Problem (want to see different

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76397] Re: Number of Differing Digits & Another Problem (want to see different
  • From: Szabolcs <szhorvat at gmail.com>
  • Date: Mon, 21 May 2007 06:03:26 -0400 (EDT)
  • Organization: University of Bergen
  • References: <f2mf5b$mbm$1@smc.vnet.net>

VenDiddy at gmail.com wrote:
> BitDifferences[a_, b_, n_] :=
>  Count[Equal @@@
>    Thread[{IntegerDigits[a, 2, n], IntegerDigits[b, 2, n]}], True]
 >
> I want to see how you would do it so I can broaden my Mathematica
> perspective.

A procedural approach:

bitDifferences[a_, b_, n_] := Module[
   {digsA = IntegerDigits[a, 2, n], digsB = IntegerDigits[b, 2, n]},
   Sum[Boole[digsA[[i]] != digsB[[i]]], {i, n}]
]


  • Prev by Date: Weird result in Mathematica 6
  • Next by Date: Re: little help needed
  • Previous by thread: Re: Number of Differing Digits & Another Problem (want to see different
  • Next by thread: Pisot Numbers