Convert Base64 Sensor String to individual numbers (half bytes?)

Hi there,

  1. I’m getting sensor data as a Base64 encoded string:

  2. If I decode this I get the following bytes:
    <<2, 99, 72, 25, 22, 54>>

  3. If I now encode16 this again to get hex values, I get:

Where the digits has the following semantics:

I’m not sure if this really makes sense - however:

My question is: Can I somehow get the individual digits directly from Step 2 by extracting the half bytes or so?
I’m a bit confused so I’m not sure if the line of reasoning is correct…

Thank you!

You can pattern match on the decoded binary:

<< first::size(4), second::size(4), ..... >> = Base.decode!(string)

This will pick the first 4 bits and put it in the first variable, the same with second and so on.

1 Like

Ah thank you, I tried something related:

<<first, bytes::binary>> = bytes

but this didn’t work, if I use:
<<first, bytes::bits>> = bytes

The docs are a bit confusing here