05-16-2010 02:14 AM
I've just started learning about binary files using Labview 8.5. I tried converting a text spreadsheet file with numbers like below (about 1000) to a binary file and then read that file in to see if it's working correctly. Seems to be doing so except that the binary file is slightly larger than the original text file. I thought that binary files were much smaller. Am I missing something? I've attached a picture of the code I've been playing around with.
250
0.105
-0.103
-0.115
0.145
-0.109
0.029
-0.126
-0.043
05-16-2010 04:35 AM
Hi ratkindler,
writing DBLs to a binary file needs 8 bytes per value, writing 1000 DBLs will need atleast 8kB...
When writing the same numbers as Spreadsheet file using a format like "%6f" will also need 7-8 chars per number resulting in slightly less than 8kB for the same array.
Binary files might be smaller when the textfile contains the numbers in same high precision (like %16)... Think about it...
05-16-2010 01:38 PM
05-16-2010 03:08 PM
05-17-2010 11:43 AM
Hi ratkindler,
The resulting size of the file is dependent on the data and the datatype being written.
For example, if you had a 100 DBLs with a value of 1000, writing that to a binary file would still result in a file size of 100 * 8 bytes = 800 bytes. However, if you had 100 U8s with a value of 1000, writing that to a binary file would result in a file size of 100 * 1 byte = 100 bytes.
If you were to write the data from either scenario to a text file, each digit would have to be converted to its ASCII representation and would result in a file size of 100* 4 bytes (1 byte per digit) = 400 bytes.
Please let me know if you have any questions. Thanks!
Aaron P
National Instruments
Applications Engineer
05-17-2010 11:54 AM
Aaron,
How do you get a value of 1000 into a U8?
Lynn
05-17-2010 11:59 AM
Hi johnsold,
Touché . Thank you for pointing out my momentary mental lapse. How about a value of 256 instead of 1000? The idea is still the same, except the resulting text file would now be 300 bytes instead of 400.
Aaron P
National Instruments
Applications Engineer
05-17-2010 12:42 PM
05-17-2010 12:57 PM
Aaron,
It is Monday. Too much weekend? Or, not enough?
We do appreciate your effort to explain the differences in file sizes.
Lynn
05-17-2010 01:26 PM
Haha wow. My brain really is taking some time to get going. How about 100 instead of 256? I think that should work.
And GerdW, thank you for pointing out the delimiters.
Aaron P
National Instruments
Applications Engineer