MathGroup Archive 2001

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

Search the Archive

Re: Importing binary files

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29480] Re: Importing binary files
  • From: "Mariusz Jankowski" <mjkcc at usm.maine.edu>
  • Date: Thu, 21 Jun 2001 01:56:54 -0400 (EDT)
  • Organization: University of Southern Maine
  • References: <9gpnuq$hcq$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Willem-Jan,

This is a frequent question. Search the archives for other solutions. Here
is a simple and fast technique

In[1]:=
strm = OpenRead["d:\\mjkcc\\temp\\test.bin",
   DOSTextFormat -> False] ;


In[2]:=
dat = ReadList[strm, Byte]

Out[2]=
{49, 44, 32, 50, 44, 32, 51, 44, 32, 52}

In[3]:=
Close[strm];



Now, given the list of bytes dat, partition into pairs and combine to form
the desired 2-byte values (I have assumed that the second byte is more
significant):

In[4]:=
Map[(#1[[1]] + 256*#1[[2]] & ), Partition[dat, 2]]

Out[4]=
{11313, 12832, 8236, 11315, 13344}


Mariusz



"WJ" <wjz at wirehub.nl> wrote in message news:9gpnuq$hcq$1 at smc.vnet.net...
> Hi all,
>
> Can anyone tellme how to import an binary file (16 bits) into mathematica?
>
> Thanx,
> Willem-Jan
>
>
>
>



  • Prev by Date: Mathematica and Powerpoint
  • Next by Date: Re: AMD vs. Intel Floating Point
  • Previous by thread: Importing binary files
  • Next by thread: Re: Importing binary files