What is a binary file and how does it work? (2024)

What is a binary file and how does it work? (1)

By

  • Robert Sheldon

What is a binary file?

A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which is eight bits in length. The content must be interpreted by a program or a hardware processor that understands in advance exactly how that content is formatted and how to read the data. Binary files include a wide range of file types, including executables, libraries, graphics, databases, archives and many others.

Electronic files are typically categorized as either binary files or text files. It could be argued that text files are also a type of binary file because, like any electronic file, they're made up of sequences of bytes. However, the two are generally considered to be different types. Text files are in a human-readable format and typically adhere to specific character sets, such as Unicode.

How is a binary file used?

Binary files are not human readable and require a special program or hardware processor that knows how to read the data inside the file. Only then can the instructions encoded in the binary content be understood and properly processed.

The following screenshot shows part of the content from a file on a Mac computer. The content can be understood only by specific system architectures such as Mac. The file in this figure is a Unix executable binary file. As is typical with binary files, the file's content is a series of sequential bytes, lined up one after the other. Although we can view the bytes that make up the binary data, the file can be properly interpreted only by the target platform.

What is a binary file and how does it work? (2)

A binary file often includes some type of header that indicates the type of file. The header might include a few human-readable characters, but a binary file as a whole requires specific software or hardware to read the file and take action. On the other hand, a user can open a text file in a wide range of editors and make sense of the content without needing any special type of interpreter.

Binary files are commonly used when building applications and other types of software. However, developers do not work directly with the binary files. Instead, they build their applications in a high-level programming language such as C++ or Java. The languages use human-readable text files to define the application logic.

At certain intervals in the development process, the text files are submitted to a compiler that translates the source code into machine code, bytecode or another programming language. If the compiler generates bytecode, the bytecode will eventually be converted to machine code.

Machine code is submitted to a computer's processor in the form of binary files. The machine code files must target a specific computer platform, which refers to the combination of operating system and hardware architecture. For example, the binary machine code might target Windows and the Intel line of microprocessors, or it might target macOS and the Apple M-series chips. A different compiler is usually required for each computer platform.

In general, executable -- or ready-to-run -- programs are identified as binary files and given a filename extension such as .bin or .exe. Programmers often talk about an executable program as a binary or will refer to their compiled application files as binaries. These types of files might also be referred to as object code.

In terms of transmitting files from one place to another, a file can be transmitted as a binary, meaning the programs handling it don't attempt to look within it or change it. Instead, they just pass it along as a chunk of ones and zeros, the meaning of which is unknown to any network device.

Learn the differences between interpreted vs. compiled languages, declarative vs. imperative programming and Kotlin vs. Swift open source programming languages.

This was last updated in June 2022

Continue Reading About binary file

  • Assess low-code platform pros and cons
  • In-demand programming languages devs should get to know
  • 11 cloud programming languages developers need to know
  • The basics of working with declarative programming languages
  • Important DevOps engineer programming languages to learn

Related Terms

CQRS (command query responsibility segregation)
CQRS (command query responsibility segregation) is a programming design and architectural pattern that treats retrieving data and...Seecompletedefinition
domain-driven design (DDD)
Domain-driven design (DDD) is a software development philosophy centered around the business domain, or sphere of knowledge, of ...Seecompletedefinition
software
Software is a set of instructions, data or programs used to operate computers and execute specific tasks.Seecompletedefinition
What is a binary file and how does it work? (2024)

FAQs

What is a binary file and how does it work? ›

A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which is eight bits in length. The content must be interpreted by a program or a hardware processor that understands in advance exactly how that content is formatted and how to read the data.

What is the difference between a binary file and a regular file? ›

At the user level, the primary difference between binary and text files is text files store data in human-readable format, and binary files are stored in binary form, i.e., 0s and 1s. If you open a text file, you can see data that an average human can understand.

What is a binary file used for? ›

Binary files can be used to store any data; for example, a JPEG image is a binary file designed to be read by a computer system. The data inside a binary file is stored as raw bytes, which is not human readable.

Is a PDF a binary file? ›

PDF files are either 8-bit binary files or 7-bit ASCII text files (using ASCII-85 encoding). Every line in a PDF can contain up to 255 characters.

What is the difference between a text file and a binary file? ›

What is the difference between a text file and a binary file? A text file is a file that contains plain text data, while a binary file is a file that contains data in a binary format. Binary files are typically used to store data that is not text-based, such as images, audio, and video.

How do you tell if a file is a binary file? ›

In general, executable -- or ready-to-run -- programs are identified as binary files and given a filename extension such as . bin or .exe.

What is the advantage of binary file? ›

1 Binary file structure. One of the advantages of binary files is that they are more efficient. In terms of memory, storing values using numeric formats such as IEEE 754, rather than as text characters, tends to use less memory. In addition, binary formats also offer advantages in terms of speed of access.

What reasons would justify the use of binary files? ›

All forms of data can be represented in binary system format. Other reasons for the use of binary are that digital devices are more reliable, small and use less energy as compared to analog devices.

Is binary file human readable? ›

The binary file you gave (since it's a compiled program) isn't just a binary representation of ASCII or any other text code. The reason is that It's machine code, meaning that it doesn't translate into anything human readable.

How do I read a binary file? ›

The steps involved in reading data from a binary file are the same as for reading data from a text file: Create an input stream and open the file, read the data, close the file. The main difference lies in the way you check for the end-of-file marker in a binary file.

Are JPEG files binary? ›

These may have readable text embedded inside, but still considered binaries. A JPEG is a binary file.

Is word a binary file? ›

doc (an abbreviation of "document") is a filename extension used for word processing documents stored on Microsoft's proprietary Microsoft Word Binary File Format; it was the primary format for Microsoft Word until the 2007 version replaced it with Office Open XML . docx files.

How do you write a binary file? ›

To write a binary file, you need to use the built-in open() function with a mode parameter of wb . This will open the file in binary mode, allowing you to write binary data to it. Here are the steps to write a binary file: Open the file in binary mode using the open() function with a mode parameter of wb .

What does a binary file look like? ›

Binary files are usually thought of as being a sequence of bytes, which means the binary digits (bits) are grouped in eights. Binary files typically contain bytes that are intended to be interpreted as something other than text characters.

How do I convert a binary file to a text file? ›

Here are some ways to convert a binary file to text:
  1. Use the nfacmd.sh command: Use the command /infacmd.sh ConvertLogFile -in /unix path/wf_name. ...
  2. Use an online converter: Use a free online converter like Duplichecker.com or SEOMagnifier to convert binary to text.
Feb 8, 2024

Are binary files processed faster than text files? ›

Answer: A binary file is usually very much smaller than a text file that contains an equivalent amount of data. I/O with smaller files is faster, too, since there are fewer bytes to move. A DVD would not have room enough to store a movie if the data were stored in character format 3.

Is every file a binary file? ›

As far as the computer is concerned, it's all binary. As to what they mean, it's all a matter of intepretation. On modern operating systems, there is no distinction at the file system level between text files and binary files.

What is the difference between binary and non binary files? ›

In computing, binary data is fundamental because computers use binary digits, or bits, to store and process information. For example, in binary, the number 5 is represented as 101. On the other hand, non-binary data encompasses information that is not restricted to two possible values.

How are binary and source files different? ›

A binary release is the compiled class files, whether in a jar file or not. A source release is the source code (. java) files, which could also be in a jar file.

What is the difference between a binary file and an executable file? ›

A binary is a file containing linked object code, an executable is a file with the executable permission bit set. All binaries should be executable (although not necessarily an executable), but not all of them do anything useful when executed.

Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 5919

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.