Binary Data In Elixir — Tentamen Software Testing Blog

Image for post
Image for post
Elixir Binary Data



5 = 101.

We need three binary digits to represent number five. You can read more about binaries in our previous post, Binary Numbers and Binary Numbers Arithmetic.

Elixir is using special operators for representing binaries: << >>. We can use numbers from -255 to 255 because each number represents a byte and byte has eight bits.

255 = 1 1 1 1 1 1 1 1

In the picture above, we first defined three binary number of two bytes.

When we try to use a number higher than 255, Elixir automatically subtracts 256 from that number without any error. Be aware of that because this could be a source of software errors.

We can also use -1. In this case, 256 is automatically added.

It is also possible to override size of one byte for each number separately.

Originally published at on August 27, 2020.

Written by

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store