Re: Importing binary files
- To: mathgroup at smc.vnet.net
- Subject: [mg29519] Re: Importing binary files
- From: "Richard" <wzn at jongnederland.nl>
- Date: Sat, 23 Jun 2001 01:46:59 -0400 (EDT)
- References: <9gpnuq$hcq$1@smc.vnet.net> <9gs35k$k4l$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Is it also possible to read two byte at once?
By a similar problem I tried to use ReadListBinary[]. This turned out to be
a lot slower.
Greetz,
Richard.
Mariusz Jankowski <mjkcc at usm.maine.edu> schreef in berichtnieuws
9gs35k$k4l$1 at smc.vnet.net...
> 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
> >
> >
> >
> >
>
>