- 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.
- Cocos2D-X權威指南(第2版)
- Visual FoxPro程序設計教程
- Practical DevOps
- Mastering Ubuntu Server
- Swift 3 New Features
- Learn Scala Programming
- Java Web程序設計
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- Python極簡講義:一本書入門數據分析與機器學習
- 一本書講透Java線程:原理與實踐
- 后臺開發:核心技術與應用實踐
- UX Design for Mobile
- Learning Dynamics NAV Patterns
- Scala實用指南
- Visual C++ 2017網絡編程實戰