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!

First Post!

aviagarwal1212

aviagarwal1212

Could you explain why you expect the output to be 2B467468? I tried to confirm through javascript,

Integer: 1749397227
Big-Endian Binary: 01101000 01000101 10101110 11101011
Little-Endian Binary: 11101011 10101110 01000101 01101000
Hex: EBAE4568

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

vegabook
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
dokuzbir
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement