📜  Erlang-二进制文件

📅  最后修改于: 2020-11-04 05:57:26             🧑  作者: Mango


使用称为二进制的数据结构来存储大量原始数据。二进制文件以比列表或元组更节省空间的方式存储数据,并且运行时系统针对二进制文件的有效输入和输出进行了优化。

二进制文件以整数或字符串序列的形式编写和打印,并以小于和大于括号的两倍括起来。

以下是Erlang中二进制文件的示例-

-module(helloworld). 
-export([start/0]). 

start() -> 
   io:fwrite("~p~n",[<<5,10,20>>]), 
   io:fwrite("~p~n",[<>]).

当我们运行上面的程序时,我们将得到以下结果。

输出

<<5,10,20>>
<>

让我们看一下可用于Binaries的Erlang函数-

Sr.No. Methods & Description
1

list_to_binary

This method is used to convert an existing list to a list of binaries.

2

split_binary

This method is used to split the binary list based on the index position specified.

3

term_to_binary

This method is used to convert a term 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 the binary string

6

binary_to_float

This method is used to convert a binary value to a float value.

7

binary_to_integer

This method is used to convert a binary value to a integer value.

8

binary_to_list

This method is used to convert a binary value to a list.

9

binary_to_atom

This method is used to convert a binary value to an atom.