- Mastering Elixir
- André Albuquerque Daniel Caixinha
- 178字
- 2021-08-05 10:42:45
Binaries
A binary is group of consecutive bytes. You create them by surrounding the byte sequence with << and >>. Here we are creating a two-byte binary:
iex> <<5, 10>>
<<5, 10>>
In the decimal base, a byte can only contain values up to 255 (otherwise it overflows). If we want to store values greater that 255, we need to tell the runtime to use more space to store this binary:
iex> <<5, 256>>
<<5, 0>>
iex> <<5, 256::16>>
<<5, 1, 0>>
As you can see, when we specify the size (16 bits in this case) we can see that the output as an extra byte and the overflow didn't occur. The size doesn't have to be a multiple of 8. In that case, a binary is usually called a bitstring.
Most programmers will not handle data at such a low level, so your use of binaries may not be that frequent. However, they're extremely useful in certain scenarios, such as processing the header of a file to find a magic number and identify the file type, or even when dealing with network packets by hand.
- LabVIEW Graphical Programming Cookbook
- SOA實踐
- iOS 9 Game Development Essentials
- vSphere High Performance Cookbook
- 深入淺出Java虛擬機:JVM原理與實戰
- Responsive Web Design with HTML5 and CSS3
- C語言程序設計
- Python神經網絡項目實戰
- 硅谷Python工程師面試指南:數據結構、算法與系統設計
- Regression Analysis with Python
- Django實戰:Python Web典型模塊與項目開發
- Natural Language Processing with Python Quick Start Guide
- Shopify Application Development
- Python編程入門(第3版)
- Qt 5.12實戰