- 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.
- Learn Type:Driven Development
- 動手玩轉(zhuǎn)Scratch3.0編程:人工智能科創(chuàng)教育指南
- Amazon S3 Cookbook
- 網(wǎng)店設(shè)計看這本就夠了
- C語言程序設(shè)計
- Learning Python by Building Games
- Cybersecurity Attacks:Red Team Strategies
- Programming with CodeIgniterMVC
- Learning Material Design
- Learning Nessus for Penetration Testing
- 深入解析Java編譯器:源碼剖析與實例詳解
- Access數(shù)據(jù)庫應(yīng)用教程(2010版)
- Python應(yīng)用與實戰(zhàn)
- Drupal Search Engine Optimization
- 走近SDN/NFV