Binaries are not always strings

  • Antony Pinchbeck
  • 2018-10-05
  • Elixir

The door access project moves a lot a binaries data about. A short while ago after the project had been in the wild for 16 months an odd error appeared.

Cards that should have been valid were being rejected.

After an investigation I tracked it down to a String.reverse call.

Data from the locks need to be reversed before doing any access checking. All worked fine until one day card data like the following turned up:

<<221, 152, 120, 6>>

Now string reverse on this does what it should and returns

<<6, 120, 221, 152>>

You can see that the first two bytes are copied and not reversed. Welcome to the world of UTF chars.


If you have binary data don’t treat it like a string, even though strings are binaries!

© 2001 - 2022 Component X Software Limited All rights reserved.