elixir - Expected a truncated byte -


when pass 2 size of bits follow:

iex(11)> <<2 :: size(2)>> 

i've got output in iex(i determine size of bit)

<<2::size(2)>> 

but when write following in iex

iex(12)> <<3 :: size(2)>> 

i've got

<<3::size(2)>> 

but expected

<<1::size(2)>> 

and 4

iex(13)> <<4 :: size(2)>> <<0::size(2)>> 

i've got 0 , right, 3 why i've got 3 instead 1?

size(2) means 2 bits, can hold 4 (2^2) values: 0, 1, 2 or 3.

it seems looking store 1 bit if expected 3 become 1. that, use size(1):

iex> <<3::size(1)>> <<1::size(1)>> 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -