VOOZH about

URL: https://www.geeksforgeeks.org/dsa/what-is-binary-string/

⇱ What is Binary String? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

What is Binary String?

Last Updated : 23 Jul, 2025

A binary string is a string that only has two characters, usually the numbers 0 and 1, and it represents a series of binary digits.

Binary String Variables:

In computer programming, binary string variables are used to store binary data, which is data that is represented in a binary (base-2) format, rather than a text (base-10) format. The three most common types of binary string variables used in databases are "BINARY", "VARBINARY", and "BLOB". Here's a brief overview of each:

  • BINARY: The BINARY data type is used to store fixed-length binary data. The data that is put in the column must always be the same size and the size of the column must be defined when the table is formed. A BINARY column, for instance, can only hold binary strings that are exactly 10 bytes long if its definition is BINARY(10).
  • VARBINARY: The VARBINARY data type is similar to BINARY but allows for variable-length binary data. As a result, the data that is kept in the column can be of any size, and the column size does not need to be defined. A VARBINARY column, for instance, can store binary strings that are any size between 0 and 65, 535 bytes.
  • BLOB: The BLOB (Binary Large Object) data type is used to store large binary data objects, such as images, audio files, or video files. When the size of the data being saved surpasses the largest size permitted by the BINARY or VARBINARY data types, BLOB columns are commonly employed. BLOB columns are frequently used to store files that are too big to fit directly in a table since they can hold binary data of any size.

Properties of Binary String:

The only symbols used to create binary strings are typically 0 and 1. The following are some crucial characteristics of binary strings:

  • Length: The amount of bits in a binary string determines its length.
  • Concatenation: Concatenation can be achieved by arranging two or more binary strings one after the other.
  • Substring: Binary strings can be broken up or divided into binary strings for each substring.
  • Prefix and Suffix: A prefix is a substring that starts a binary string at the beginning. A binary string's suffix is a substring that is appended to the end of the string.
  • Hamming distance: The number of points where the corresponding symbols diverge in two binary strings of equal length is known as the Hamming distance.
  • Regular Language: The set of all binary strings is a regular language, which means that a finite state machine or regular expression can understand it.
  • Binary arithmetic: In binary arithmetic, where each bit corresponds to a power of 2, binary strings can be used to express integers.

Code Implementation:

Output:

Length of binary string 1: 8
Concatenation of binary strings: 1010101001010101
Substring of binary string 1: 1010
Prefix of binary string 1: 101
Suffix of binary string 2: 0101
Hamming distance between binary strings 1 and 2: 8
Does binary string 1 have a regular language? Yes
Binary addition of 10101010 and 01010101: 11111111

What else can you read?

Comment