MathGroup Archive 2005

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

Search the Archive

Reducing binary representation

  • To: mathgroup at
  • Subject: [mg57142] Reducing binary representation
  • From: Torsten Coym <torsten.coym at>
  • Date: Thu, 19 May 2005 03:08:09 -0400 (EDT)
  • Organization: Fraunhofer Gesellschaft (
  • Sender: owner-wri-mathgroup at

Hi MathGroup,

I want to reduce the number of coefficients in the binary representation 
of arbitrary integer numbers. I managed to convert an integer number 
into a sum of powers of two in the following way:

ToBinary[x_, n_] := Plus @@
      {Table[(HoldForm[2^#1] & )[i], {i, n - 1, 0, -1}],
       IntegerDigits[x, 2, n]}]]

ToBinary[121, 10]

HoldForm[2^0] + HoldForm[2^3] + HoldForm[2^4] +
   HoldForm[2^5] + HoldForm[2^6]

The sum of adjacent powers of two can be reduced as follows:

Sum[2^i, {i, k, j}]

2^(1 + j) - 2^k

I now want to apply that to the binary number representation, so that 
121 will become


but I cannont figure out how to do this. If I release the Hold[] 
Mathematica just evaluates all the terms containing "2" to get "121", 
which is not what I want ;)

Unfortunately I have no idea how to tackle this kind of problem. Any 
suggestion would be appreciated.
Thank you.


  • Prev by Date: Re: Beginner : how to convert .bmp or .jpeg fordigital processing
  • Next by Date: Re: Beginner : how to convert .bmp or .jpeg for digital processing
  • Previous by thread: Re: Beginner : how to convert .bmp or .jpeg fordigital processing
  • Next by thread: Re: Reducing binary representation