vitor_ferreira Posted January 11, 2017 at 04:48 PM Report #601950 Posted January 11, 2017 at 04:48 PM Boa Tarde. Antes de mais quero agradecer a toda esta comunidade pois graças e todos os que dela fazem parte comecei a programar e vou conseguindo tirar as minhas duvidas. Neste momento estou com um problema que é o seguinte. Estou a comunicar com um autómato em modbus tcp, mas recebo o valor das entradas digitais numa variável do tipo Integer. o meu problema é que ja pesquisei bastante e não consigo encontrar como converter a variável integer num array do tipo bool.
_Rest_ Posted January 11, 2017 at 05:42 PM Report #601952 Posted January 11, 2017 at 05:42 PM Não percebi bem o que pretendes. Tens um int com tipo 110101100 e queres converter para um array de bool é isso? Pode haver maneiras mais elaboradas, mas podes sempre converter num array de char e verificares char a char. Exemplo int x = 110101001; char[] t = x.ToString().ToCharArray(); bool[] a; a = new bool[t.Count()]; for(int y = 0; y < t.Count(); y++) { if (int.Parse(t[y].ToString()) == 1) a[y] = true; }
vitor_ferreira Posted January 11, 2017 at 06:49 PM Author Report #601956 Posted January 11, 2017 at 06:49 PM 1 hora atrás, _Rest_ disse: Não percebi bem o que pretendes. Tens um int com tipo 110101100 e queres converter para um array de bool é isso? Pode haver maneiras mais elaboradas, mas podes sempre converter num array de char e verificares char a char. Exemplo int x = 110101001; char[] t = x.ToString().ToCharArray(); bool[] a; a = new bool[t.Count()]; for(int y = 0; y < t.Count(); y++) { if (int.Parse(t[y].ToString()) == 1) a[y] = true; } _Rest_ é exactamente uma variável do tipo int com esse tipo de dados que recebo. Vou testar e depois digo se resulta assim. Desde já muito obrigado pela tua ajuda.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now