开发者

converting binary to text in linux

开发者 https://www.devze.com 2023-04-05 10:06 出处:网络
I have a big bina开发者_高级运维ry file I have produced by writing an array of float numbers in binary format.

I have a big bina开发者_高级运维ry file I have produced by writing an array of float numbers in binary format.

Now how can I simply convert that binary file to text ?


Use the UNIX od command, with the -t f4 option to read the file as 4 byte floating point values. The -A n option is also useful to avoid printing the file offsets. Here is the output of an example file that I created.

/tmp> od -A n -t f4 b.dump
        -999.876        -998.876        -997.876        -996.876
        -995.876        -994.876        -993.876        -992.876
        -991.876        -990.876        -989.876        -988.876
        -987.876        -986.876        -985.876        -984.876


You will need to reverse the process.

  1. Read the file back into an array of floats.
  2. Print the array use printf() or your favorite io function.

Any other approach will be ugly and painful; not to say this isn't ugly to start with.

0

精彩评论

暂无评论...
验证码 换一张
取 消