OK, then you need to glue them into an LINT or DWORD first. The "glueing" is actually a shift left, by 16Bit, and an OR of the two types. The shift is necessary to move the bits of the upper to bytes to the correct position. And the OR "merges" the two datatypes into one.
With an implicite 32 bit intermediate value:
real3 := TO_REAL(SHL(int2, 16) OR int1);
And if you want to make it very explicit:
dword4 := SHL(int2, 16);dword4 := dword4 OR int1;real3 := TO_REAL(dword4);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey! Very good idea.
Sure, you can do it like that.
I don't know why I didn't come up with that. Because, this is the most straight use-case for union π
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I want to convert 2 diff INT datatype TO 1 Real datatype.
for example:
int1: int
int2:int
real3:real
How Can convert int1&int2 TO Real3?
Thanks
Do you mean...?
real3 := TO_REAL(int2 - int1);
Didn't understand what exactly you meant with "diff" type.
I have 2 different variable data types INT : 2 Bytes from the first var =INTA and 2 Bytes from the second var=INTB, and GLUE them to REALC-float
OK, then you need to glue them into an LINT or DWORD first. The "glueing" is actually a shift left, by 16Bit, and an OR of the two types. The shift is necessary to move the bits of the upper to bytes to the correct position. And the OR "merges" the two datatypes into one.
With an implicite 32 bit intermediate value:
real3 := TO_REAL(SHL(int2, 16) OR int1);
And if you want to make it very explicit:
Can I use it like:
TYPE Convert_2_int_to_byte :UNION
i: WORD;
c:WORD;
bytes: ARRAY [0..3] OF BYTE;
END_UNION
END_TYPE
TYPE Convert_Real_to_byte :UNION
a:REAL;
bytes: ARRAY [0..3] OF BYTE;
END_UNION
END_TYPE
Hey! Very good idea.
Sure, you can do it like that.
I don't know why I didn't come up with that. Because, this is the most straight use-case for union π
Opened 2 times the same question, once in Engineering, once here ;-)
The Engineering thread is also UNION solution.