Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
Hi, I am writing a utility to take in a file with plain text and convert that into binary and outputs the result to another file. I'm thinking of writing ...
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    9

    script to convert from text file to binary

    Hi, I am writing a utility to take in a file with plain text and convert that into binary and outputs the result to another file. I'm thinking of writing it in C++ or Python. I was just wondering if there are already built in functions or library that support this already. Any inputs would be appreciated, thanks!

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    have you tried "od"?
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Apr 2010
    Posts
    9
    no, not yet, i'm not sure what 'od' is. I tried reading the plain text in and converted to hex -> decimal -> binary. Then write to a file. I had to write functions to do that. I just wonder if there are more efficient ways to do it like some built in functions.

  4. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by chaoses
    no, not yet, i'm not sure what 'od' is.
    It dump files in octal and other formats. Check its manual here.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by chaoses
    no, not yet, i'm not sure what 'od' is.
    It dump files in octal and other formats. Check its manual here.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    Just Joined!
    Join Date
    Apr 2010
    Posts
    9
    okay I did a hex dump of my program converting from ascii to binary (seeing only 0s and 1s). It is different from the hex dump of the same file in binary format (seeing junk when viewing). What's the difference between the 2 binary files and how do I convert them back to plain text?

  7. #7
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Okay, so what exactly will the conversion do? A text file is simply a file containing no 'un-printable' characters, and typically delimited by some conventional end-of-line character(s). Can you give an example of what some text, say, this post would be as 'binary'? I'm not sure your question is based on any sound understanding of how files are stored, and the representation of of digital data.

    --- rod.
    Stuff happens. Then stays happened.

  8. #8
    Just Joined!
    Join Date
    Apr 2010
    Posts
    9
    basically, I have a plain text file which contains normal characters like the ones we type here. For example

    plaintext.txt contains
    hello world

    I have another binary file that was told to be converted from plaintext.txt into binary. Its contents can not be viewed by the editors. So that file looks something like this call it file2:
    file2 (binary file)
    88>¥^QÔA^@^@^@èùÔA^@^

    I want to verify if the converted file (file2) is the binary conversion of the plain text file by writing a program to convert the plain text to binary. This file reads in the plain text and convert it into binary and compare the result of the 2. They don't look the same.

    So my question is can I use any function to revert file2 to see its contents?

  9. #9
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    You will need to know the method/algorithm/transformation function that was used to perform the translation. Is this actually some kind of compression or encryption technique? Is it a conversion to a format used by a specific tool? It is unusual for a conversion such as you describe to be performed, especially for arbitrary reason.
    --- rod.
    Stuff happens. Then stays happened.

  10. #10
    Just Joined!
    Join Date
    Apr 2010
    Posts
    9
    I don't know what method was used, but I was told it did a binary conversion from plain text file to that binary file. I wanted to verify so I wrote a program to do a binary conversion but it didn't match. I need to converted file to feed into something else but until I can verify that it was a binary conversion or whatever. I was just wonder if in fact it was a binary conversion, is there a way to go back from that format to plain text.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...