Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Please post: Mathematica -another For loop problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65805] Re: [mg65741] Please post: Mathematica -another For loop problem
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Mon, 17 Apr 2006 02:29:00 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200604160749.DAA11182@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

A functional approach:

   # + 2048*(1 - 2Boole[# > 2048]) & /@ y


1.156 wrote:
> [This post has been delayed due to email problems - moderator]
> 
> 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
> 
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: mathematica
  • Next by Date: Re: Please post: Mathematica -another For loop problem
  • Previous by thread: Please post: Mathematica -another For loop problem
  • Next by thread: Re: Please post: Mathematica -another For loop problem