I have time deltas stored in a file in two formats:
In the first format, the time delta is the unsigned 7 bit field represented by xxxxxxx. In the second format, the time delta is the signed 15 bit field represented by yyyyyyyyyyyyyyy
pattern matching to extract the values works for the 7 bit unsigned case:
iex(12)> <<0::1, num::size(7)-unsigned-integer-little>> = <<2>>; num 2
But for the intuitive extension to the 15-bit signed case, it isn’t so obvious that it is working correctly:
iex(15)> <<1::1, num::size(15)-signed-integer-little>> = <<255,255>>; num -1
That’s reasonable. However:
iex(14)> <<1::1, num::size(15)-signed-integer-little>> = <<254,255>>; num -3
The value of the 15 bit signed field is -2, not -3.
I’ve been searching for the documentation fruitlessly, so a pointer to the place where I can read the fine documentation, or else just the answer, would be appreciated.