arruah

arruah

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!

Showing Posts 1 to 4

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

adamu

adamu

Are you using AI by any chance?

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

arruah

arruah OP

Sorry, It looks like my AI fooled me.

adamu

adamu

At least we identified the deep environmental problem :grin:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews