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

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement