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
Also Liked
kip
ex_cldr Core Team
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
Last Post!
kip
ex_cldr Core Team
Popular in Questions
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
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
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
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
Latest Nerves Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









