MathGroup Archive 2006

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

Search the Archive

Re: For Loop problem

  • To: mathgroup at
  • Subject: [mg65630] Re: [mg65595] For Loop problem
  • From: bsyehuda at
  • Date: Tue, 11 Apr 2006 04:04:45 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

First to make it more efficient than using For loops , which are the slowest
loops in Mathematica, you can Map the function over y
y=If[#>2048,#-2048,#+2048]&/@ y
will change it
You didn't mention if the numbers are unsigned or signed, and in case of
signed numbers are they represented in 1's complement or 2's complement or
just a signed bit.
2048 is the most significant bit in your 12-bit representation, so I would
expect it to be zero for number SMALLER then 2048, practically unchanged, so
I wonder why do you add 2048 in this case?
To the best of my understanding you are inverting the sign bit of these
numbers. Is it really what you whant to do?

On 4/10/06, Rob <rob at> wrote:
> I've got to manipulate some signed 12bit integer numbers from a file and
> apparently Mathematica only handles 8 and 16 bit signed numbers
> (probably for a very good reason). So I bring them in as 16 bits (and
> they're stored that way with a leading zero nibble) and then I have to
> do the following to make sense of them.  I really don't know why this
> code works but it does.
> For[i = 1, i < Length[y], i++, If[y[[i]] > 2048, y[[i]] =
>      y[[i]] - 2048, y[[i]] = y[[i]] + 2048]];
> So to my question: once again I had to resort to a For loop to pull this
> off and I know this is a no-no.  But I'm so clueless about Mathematica
> that I've never come up with a more sophisticated method after a year or
> so of thinking about it. Can someone help (as they usually can)?
> Thanks, Rob

  • Prev by Date: Re: For Loop problem
  • Next by Date: Re: Code problem
  • Previous by thread: Re: For Loop problem
  • Next by thread: Re: For Loop problem