Zesky665
How to parse bitstring?
Hi,
Anyone know how to parse a bitstring?
I have values like this : <<170, 192, 65, 0, 100, 0, 61, 86, 56, 171>> coming in from a sensor.
I need to get 65 ad 100 out to of that without changing them to another number. Anyone have an idea as to how to do that?
Thanks
Marked As Solved
kip
ex_cldr Core Team
Here you go:
iex> :binary.bin_to_list x
[170, 192, 65, 0, 100, 0, 61, 86, 56, 171]
4
Also Liked
kip
ex_cldr Core Team
Yes, it is. Everything in Erlang is available in Elixir.
3
kip
ex_cldr Core Team
Something like this:
iex> x = <<170, 192, 65, 0, 100, 0, 61, 86, 56, 171>>
iex> << _ :: bytes-4, onehundred :: bytes-1, _ :: bytes-1, sixtyone :: bytes-1, _rest :: binary >> = x
<<170, 192, 65, 0, 100, 0, 61, 86, 56, 171>>
iex> onehundred
"d"
iex> sixtyone
"="
This assumes you want the fields as binaries. If you want them as integers:
iex> << _ :: bytes-4, onehundred :: size(8), _ :: bytes-1, sixtyone :: size(8), _rest :: binary >> = x
<<170, 192, 65, 0, 100, 0, 61, 86, 56, 171>>
iex> sixtyone
61
iex> onehundred
100
2
Popular in Questions
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
I am trying to implement my new.html.eex file to create new posts on my website.
new.html.eex:
<h1>Create Post</h1>
<...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
I'm brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "eq...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I'm a nov...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New







