Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

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

Search the Archive

Re:Inputting integer data in binary form

  • To: mathgroup at
  • Subject: Re:Inputting integer data in binary form
  • From: John Novak <novak>
  • Date: Wed, 20 May 1992 08:09:00 -0500

>I'm working on a Sun system with Mathematica 1.2.  I need to input
>a file of integer data which I have in binary form, two bytes per
>integer.  Can anyone make any suggestions about how to do this?
This one is fairly easy; read it in as bytes, and convert those to integers, as

Apply[256 #1 + #2 &, Partition[ReadList["filename",Byte],2],{1}]

This should give you a list of integers that were originally two bytes,
unsigned.  Various modifications can be made to this to handle, say, signed
integers, or little-endian storage.

>More generally, are there Mathematica functions or packages for
>inputting other types of binary files, containing, for example,
>four byte integers, four byte floating, eight byte floating,
Coming soon in the next version of Mathematica, there will be a package called
Utilities`BinaryFiles`.  This defines functions ReadBinary, ReadListBinary, and
WriteBinary (amongst others); it will handle all the types you mention.

Hope this is useful!
--John N.
John M. Novak                                                             
novak at
Wolfram Research, Inc.

  • Prev by Date: Re: Hardware Mma ?
  • Next by Date: Finding effective directive of a graphics primitive
  • Previous by thread: Inputting integer data in binary form
  • Next by thread: Inputting integer data in binary form