MathGroup Archive 2007

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

Search the Archive

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


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