Binaries pattermatching problem

Hello,

Actually I’m having a strange problem with binaries, I’m reading binaries from a socket, all seems to be fine except to get negative numbers, here is a example:

iex(13)> <<test::32>> = <<-1::32>>
<<255, 255, 255, 255>>
iex(14)> test
4294967295
iex(15)>

I expect to have a negative value, but it return the max unsigned value, how I can fix this?

Greetings!

iex(4)> <<test::signed-32>> = <<-1::32>>
<<255, 255, 255, 255>>
iex(5)> test
-1
2 Likes

so many thanks!

I have been sure that there has to be a qualifier for signed integers, but wasn’t able to find the page that lists them all yesterday. Because of that I didn’t chime in here but have waited for someone else to answer.

Can you please link to the corresponding documentation?

1 Like

It’s in the docs for Kernel.SpecialForms: <<args>> under the Modifiers section.

2 Likes