Hi,
...but it's not cute!
Pascal
I dunno, but if you figure it out on CCW, I am pretty sure you will be the first!How I can do this with "COP" function ...
How I can do this with ... loop instruction?
Datalogix[1] := 0;
Datalogix[2] := 0;
dint_mask := 1;
for index := 0 to 7
Datalogix[1] := Datalogix[1] + (dint_mask * ANY_TO_DINT(Output[index]));
Datalogix[2] := Datalogix[2] + (dint_mask * ANY_TO_DINT(Output[index+8]));
dint_mask := dint_mask + dint_mask;
if dint_mask = 128 then
dint_mask := -128;
end_if;
end_for;
Datalogix[1] := 0;
Datalogix[2] := 0;
for index := 0 to 15
subscript := 1 + ANY_TO_DINT(index.8);
Datalogix[subscript] := Datalogix[subscript] + (dint_mask * ANY_TO_DINT(Output[index]));
dint_mask := dint_mask + dint_mask;
if dint_mask = 128 then
dint_mask := -128;
elif dint_mask = -256 then
dint_mask := 1;
end_if;
end_for;
USINTArray[0] := 0;
USINTArray[1] := 0;
FOR i := 0 to 7 DO
IF BoolArray[i] THEN
USINTArray[0] := USINTArray[0] + SHL(1, i);
END_IF;
END_FOR;
FOR i := 8 to 15 DO
IF BoolArray[i] THEN
USINTArray[1] := USINTArray[1] + SHL(1, i-8);
END_IF;
END_FOR;
Whilst there is more that one to skin a cat, for 16 bools, i'd just leave it to what you have done.
KISS.
USINTArray[0] := 0;
USINTArray[1] := 0;
FOR i := 0 to 7 DO
IF BoolArray[i] THEN // Si le bit est vrai, on procède au décalage vers la gauche
Resultat_DINT:= SHL(1, i); // La variable Resultat doit etre de type DINT...
USINTArray[0] := USINTArray[0] + ANY_TO_USINT(Resultat_DINT);//Resultat_USINT; //+ SHL(1, i);
END_IF;
END_FOR;
FOR i := 8 to 15 DO // Pour la 2e variable, même principe...
IF BoolArray[i] THEN
Resultat_DINT:= SHL(1, i-8);
USINTArray[1] := USINTArray[1] + ANY_TO_USINT(Resultat_DINT); //SHL(1, i-8);
END_IF;
END_FOR;
I need to modify, little bit your code ojz0r because SHL instruction need DINT. The code work whell. I must watch SHL instruction so mush...
Incidently my favourite languagePascal
USINTArray[0] := 0;
USINTArray[1] := 0;
FOR i := 0 to 7 DO
IF BoolArray[i] THEN // Si le bit est vrai, on procède au décalage vers la gauche
Resultat_DINT:= SHL(1, i); // La variable Resultat doit etre de type DINT...
USINTArray[0] := USINTArray[0] + ANY_TO_USINT(Resultat_DINT);//Resultat_USINT; //+ SHL(1, i);
END_IF;
IF BoolArray[i+8] THEN
Resultat_DINT:= SHL(1, i);
USINTArray[1] := USINTArray[1] + ANY_TO_USINT(Resultat_DINT); //SHL(1, i);
END_IF;
END_FOR;
Incidently my favourite language
You are the first person I can remember who says this. I very much sympathize with this, although I choose ladder for certain applications.
First the 16 BOOL is that a true array of 16 or a INT data type?
Data type INT and an array of 1 BOOL
if it's a INT data type just use the COP function
Source is the INT data type
Destination is a USINT[0] data type
Lenght woud be 2
bits 0 -7 would be in USINT [0]
bits 8 - 15 would be in USINT [1]