       Reducing binary representation

• To: mathgroup at smc.vnet.net
• Subject: [mg57142] Reducing binary representation
• From: Torsten Coym <torsten.coym at eas.iis.fraunhofer.de>
• Date: Thu, 19 May 2005 03:08:09 -0400 (EDT)
• Organization: Fraunhofer Gesellschaft (http://www.fraunhofer.de/)
• Sender: owner-wri-mathgroup at wolfram.com

```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:

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

In:=
ToBinary[121, 10]

Out=
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:

In:=
Sum[2^i, {i, k, j}]

Out=
2^(1 + j) - 2^k

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

2^7-2^3+2^0

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.

Torsten

```

• 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