LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is my binary file saved as ASCII?

Solved!
Go to solution

Hi,

 

I open a text file (file.txt) and try to save it as a binary (file.bin). It just creates another ASCII file. Both look the same in Notepad. What am I doing wrong?

 

Convert ACII to Binary.jpg

Thanks!

 

Shok

0 Kudos
Message 1 of 8
(4,753 Views)
Solution
Accepted by topic author Shok

A "text" file is a binary file.  A byte is a character, a character is a byte.  What shows on the screen in notepad is determined by the ASCII table mapping.

 

What did you expect to see differently in your "binary" file when you used Read Text File to read the data and sent the data without changing anything about it to the Write Binary file function?

Message 2 of 8
(4,746 Views)

In general text file is binary byte file where each byte is ASCII symbol, so you have the same content. If you would like to get "unreadable" binary file, just convert string to byte array, then perform xor operation. When opened, perform xor operation again and you will get your text back. What you expect to get in general? 

 

Andrey.

 

0 Kudos
Message 3 of 8
(4,738 Views)

There is one important difference between writing or reading a binary file versus text, and that is that end-of-line handling.  When you write a line to a text file, the write function will write the appropriate end-of-line character, which is different on Windows, Mac, and Unix.  This isn't a difference in the file itself, it's a difference in the functions used to access it.

0 Kudos
Message 4 of 8
(4,738 Views)

Nathan, Not true. The LabVIEW Write text file function writes out exactly what you have in that string.  No more, no less.  If you want the appropriate end of line character, you have to explicity add it yourself.

0 Kudos
Message 5 of 8
(4,732 Views)

@Ravens Fan wrote:

Nathan, Not true. The LabVIEW Write text file function writes out exactly what you have in that string.  No more, no less.  If you want the appropriate end of line character, you have to explicity add it yourself.


It's mostly true.  Drop a Write to Text File on a block diagram and right click on it.  The "Convert EOL" item is checked by default.  Admittedly if you uncheck it, it will write your input exactly, but the default behavior is to convert end of line characters.

0 Kudos
Message 6 of 8
(4,729 Views)

Let's clarify.

 

The Write to Text File does not ADD any kind of end of line character.  I wrote the data "xx".  That is exactly what it put in the file. 2 bytes

 

Now if you do send data that includes an end of line character in it,  "xx\r"  (slash code mode, 3 bytes) then it will convert the \r to a \r\n in Windows when the Convert EOL character is setting is on and the file will contain 4 bytes.

Message 7 of 8
(4,724 Views)

I guess I was expecting hex data or something.

 

Thanks!

0 Kudos
Message 8 of 8
(4,721 Views)