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.

See Also
HL7 Messages

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

change control
Change control includes the various steps needed to process changes made to a product or system. Completion of change controls in...Seecompletedefinition
entity relationship diagram (ERD)
An entity relationship diagram (ERD), also known as an 'entity relationship model,' is a graphical representation that depicts ...Seecompletedefinition
web services
Web services are a type of internet software that use standardized messaging protocols and are made available from an application...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 file and a binary file? ›

The text files can easily be transferred from one computer system to another. Binary files cannot easily be transferred from one computer system to another due to variations in the internal variations in the internal representation which varies from computer to computer.

What is binary data and how does it work? ›

In statistics, binary data is a statistical data type consisting of categorical data that can take exactly two possible values, such as "A" and "B", or "heads" and "tails". It is also called dichotomous data, and an older term is quantal data. The two values are often referred to generically as "success" and "failure".

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

A text file is processed as a sequence of characters. A binary file is processed as a sequence of bytes. In a text file you have the illusion that the file is divided into lines. There is a special end-of-line symbol that creates this illusion.

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

Text files and Binary files are two types in which the computer stores the data. 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.

What is the purpose of a binary file? ›

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.

What is an example of a binary file? ›

For example, only Microsoft Word and certain other word processing programs can interpret the formatting information in a Word document. Executable files, compiled programs, SAS and SPSS system files, spreadsheets, compressed files, and graphic (image) files are all examples of binary files.

How does binary work for dummies? ›

The binary system is a way of representing data using 0s and 1s. This system is used by computers to represent all the data it works with. To compute a number in this system, you would multiply the digit value by the place value, then add them all together.

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.

What is the purpose of using binary? ›

The binary number system is the base of all computing systems and operations. It enables devices to store, access and manipulate all types of information directed to and from the CPU or memory.

How do I read text from a binary file? ›

After opening the binary file in binary mode, we can use the read() method to read its content into a variable. The” read()” method will return a sequence of bytes, which represents the binary data.

Which is faster text file or binary file? ›

Answer: A binary file is usually very much smaller than a text file that contains an equivalent amount of data. ... Small files save storage space, can be transmitted faster, and are processed faster.

Is PDF binary or text? ›

PDF is NOT a text format. PDF is a binary format, and simply opening it in a text editor does not give you any suvvicient information about parsing.

How do I know if a file is binary or text? ›

Check to see if there are any 0a0d byte combinations - binary files shouldn't contain linefeed/carriage return pairs. Hi, The only sure way is to read the data and then compare it with some arbitrary values to see if any of the data is outside of what is considered a text file.

Is a JPEG a binary file? ›

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.

How to create a binary file? ›

Until the end of the text file is reached perform the following steps:
  1. Read a line from the input text file, into 3 variables using fscanf().
  2. The structure variable is set to values for elements(to write the structure variable into the output file.
  3. Write that structure variable to the output binary file using fwrite().
Jul 21, 2021

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

A text file contains data that has been encoded as text using a scheme such as unicode. The file may be opened and viewed in a text editor such as notepad. A binary file contains data that has not been converted to text. You cannot view the contents of binary file with a text editor.

Can any file be a binary file? ›

Compiled computer programs are typical examples; indeed, compiled applications are sometimes referred to, particularly by programmers, as binaries. But binary files can also mean that they contain images, sounds, compressed versions of other files, etc. – in short, any type of file content whatsoever.

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

Binary data-It is the data in the form of 0 and 1 which is otherwise known as machine language i. e. it can be understood by the machine. Non-binary data is the source code in the form of alphabets, digits, or special characters which is provided by the user.

Is a PDF file a binary file? ›

General conventions

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.

Top Articles
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 6357

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.