English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang Binary Files

Use a binary data structure called binary to store a large amount of raw data. Binary files store data in a more space-saving way than lists or tuples, and the runtime system is optimized for efficient input and output of binary files. Binary files are written and printed in the form of an integer or string sequence, enclosed in less than or greater than brackets.

The following is an example of a binary file in Erlang−

Online Example

-module(helloworld). 
-export([start/0]). 
start() -> 
   io:fwrite("~p~n",[<<5,10,20>>]), 
   io:fwrite("~p~n",[<<"hello">>]).

Output Result:

<<5,10,20>>
<<"hello">>

Let's see the Erlang functions that can be used to handle binary files -

Serial NumberMethods and Descriptions
1

list_to_binary

This method is used to convert an existing list to a binary list.

2

split_binary

This method is used to split a binary list according to the specified index position.

3

term_to_binary

This method is used to convert terms to binary.

4

is_binary

This method is used to check if a bitstring is indeed a binary value.

5

binary_part

This method is used to extract a part of a binary string.

6

binary_to_float

This method is used to convert binary values to floating-point values.

7

binary_to_integer

This method is used to convert binary values to integer values.

8

binary_to_list

This method is used to convert binary values to lists.

9

binary_to_atom

This method is used to convert binary values to atoms.