in reply to Writing Out Binary Files

Try telling us the what & why of what you are trying to do, rather than the how you are trying to do it.

Eg. You have a long list of floating point numbers that you wish to send to another machine and that machine expects them to be in binary form.

Or: You have a long list of numbers that you wish to save to disk, but you would prefer them to be more compact.

Or: You have a some binary data that you wish to send someone by email, and want to avoid corruption caused by the stripping of the high order bit.

Each of these is a possible scenario from what you have said and shown so far, but each requires a different solution.

A clearer question will get you better answers (and ruffle less feathers:). This is little different from what a lot of other people have already said, but maybe it is worded a little more clearly?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Writing Out Binary Files
by Anonymous Monk on May 08, 2003 at 17:28 UTC
    And the selection is:
    I have a long list of numbers that you wish to save to disk,
    but you would prefer them to be more compact.
    Actually every reply so far has been quite helpful!
    Thanks Again!

      In that case, you should probably be looking at the 'F' or 'D' pack/unpack format specifiers depending upon your needs regarding space versus accuracy.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller