arruah

arruah

Extremely Puzzling: Elixir Bitstring little-integer Encoding Issue (Confirmed in iex after Reinstall)

Hello everyone,

I’m encountering a truly baffling and persistent issue with Elixir’s bitstring syntax for little-endian integer encoding, and I’m hoping someone here might have seen something similar or can
shed some light on it.

The Problem: When attempting to convert a specific 32-bit unsigned integer (1749397227) to its little-endian binary representation, both the direct bitstring syntax
(<integer::unsigned-little-integer-size(32)>) and Erlang’s :binary.encode_unsigned(:little) function produce an incorrect byte order on my system.

• The integer 1749397227 in hexadecimal is 0x6874462B.
• Its correct Little-Endian binary representation should be <<0x2B, 0x46, 0x74, 0x68>>, which is “2B467468” in hex.

However, my system consistently produces <<0xEB, 0xAE, 0x45, 0x68>>, which is “EBAE4568” in hex.

Minimal iex Reproduction:

Please run these lines in your iex session and share the output:

my_int = 1749397227                                                                                                                                                                            
le_bin = <<my_int::unsigned-little-integer-size(32)>>                                                                                                                                          
expected_hex = "2B467468"                                                                                                                                                                      
actual_hex = Base.encode16(le_bin)                                                                                                                                                             
                                                                                                                                                                                               
IO.puts("--- Bitstring Test ---")                                                                                                                                                              
IO.puts("Integer:    #{my_int}")                                                                                                                                                               
IO.puts("Expected LE: #{expected_hex}")                                                                                                                                                        
IO.puts("Actual LE:   #{actual_hex}")                                                                                                                                                          
IO.puts("Match:       #{actual_hex == expected_hex}")                                                                                                                                          
                                                                                                                                                                                               
# Also test Erlang's :binary module                                                                                                                                                            
erlang_le_bin = :binary.encode_unsigned(my_int, :little)                                                                                                                                       
erlang_actual_hex = Base.encode16(erlang_le_bin)                                                                                                                                               
IO.puts("\n--- Erlang :binary Test ---")                                                                                                                                                       
IO.puts("Expected LE: #{expected_hex}")                                                                                                                                                        
IO.puts("Actual LE:   #{erlang_actual_hex}")                                                                                                                                                   
IO.puts("Match:       #{erlang_actual_hex == expected_hex}")

My Observed Output (consistently):

— Bitstring Test —
Integer: 1749397227
Expected LE: 2B467468
Actual LE: EBAE4568
Match: false

— Erlang :binary Test —
Expected LE: 2B467468
Actual LE: EBAE4568
Match: false

Troubleshooting Steps Taken (Extensive):

1 Confirmed source code (lib/util/crypto.ex) uses the correct bitstring syntax.
2 Confirmed manual bitwise operations (<<val &&& 0xFF, …>>) do produce the correct “2B467468” when run directly in iex.
3 Performed multiple mix clean --all and rm -rf _build deps priv/repo/migrations.
4 Performed a complete reinstallation of Elixir and Erlang/OTP using asdf (uninstalling, clearing ~/.asdf/downloads and build caches, then reinstalling stable Erlang 27.0 and Elixir
1.18.3-otp-27).
5 Confirmed elixir --version shows the newly installed versions.
6 Ran mix test and direct function calls in iex -S mix after each step.

Despite all this, the issue persists. This suggests a very deep environmental problem.

My System Information:

• elixir --version output: (Paste your actual output here, e.g., Erlang/OTP 27 [erts-15.2.3] … Elixir 1.18.3 (compiled with Erlang/OTP 27))
• Operating System: (e.g., Ubuntu 22.04 LTS)
• CPU Architecture: (e.g., x86_64, ARM64)

Has anyone ever encountered such a fundamental and persistent issue with bitstring encoding in Elixir/Erlang? Any insights or further diagnostic steps would be greatly appreciated!

Thank you!

Most Liked

adamu

adamu

At least we identified the deep environmental problem :grin:

adamu

adamu

Are you using AI by any chance?

This is not true. 1749397227 in hexadecimal is 0x6845AEEB.

arruah

arruah

Sorry, It looks like my AI fooled me.

Where Next?

Popular in Questions Top

senggen
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
baxterw3b
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement