Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Why are there Four Extra Bytes in the Beginning of my Binary File?

Primary Software: LabVIEW Development Systems>>LabVIEW Base Package
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I am using the LabVIEW Write to Binary File VI.  When viewing this file in a hex editor, there are four extra bytes of information at the beginning of the file.  Why is this?

Solution:
The first four bytes in the binary file represent how many elements of data are in the binary file. For example, if you write an array of 10 integers in I32 format to a binary file, the first four bytes will have the value 10. This is to tell the program reading the file that there are 10 elements in the file. In the picture below, we are writing an array of 10 integers (I32 format) to a binary file.

This file produces the following text in a hex editor.

The first four bytes, highlighted in black, represent the number of elements (integers) in the file.  The number 00 00 00 0a represents the number 10 in hex, telling us that there are 10 integers in this file.

The next four bytes represent the first number written to the file.  So the number 00 00 00 01 represents the number 1 in hex, tellling us the first integer written to the file is a 1.  The rest of the data, integers 2 through 10 follow.

Related Links:
LabVIEW 8.6 Help: Write to Binary File Function
LabVIEW 8.6 Help: Writing to Binary Files


Attachments:


write_to_binary.JPG - write_to_binary.JPGhex_view.JPG - hex_view.JPG



Report Date: 01/20/2007
Last Updated: 07/10/2009
Document ID: 45JDON4G

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit