<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/</id><updated>2021-08-17T10:15:01.443000Z</updated><subtitle>Recent posts to Convert 2 diff type of int to real type</subtitle><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=250#3c86" rel="alternate"/><published>2021-08-17T10:15:01.443000Z</published><updated>2021-08-17T10:15:01.443000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.coma2293715056843d00fc5ebdfdd2e1d35060b09eb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Opened 2 times the same question, once in Engineering, once here ;-)&lt;br/&gt;
The Engineering thread is also UNION solution.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=25#f878/0794/d2d6/0fb7/6e19/5e6f" rel="alternate"/><published>2021-08-17T08:30:02.093000Z</published><updated>2021-08-17T08:30:02.093000Z</updated><author><name>Ingo</name><uri>https://forge.codesys.com/u/ingo/</uri></author><id>https://forge.codesys.comeef8fa20c88bedb0c7aa803d71468238d11e29e5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hey! Very good idea.&lt;br/&gt;
Sure, you can do it like that.&lt;br/&gt;
I don't know why I didn't come up with that. Because, this is the most straight use-case for union 😉&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=25#f878/0794/d2d6/0fb7/6e19" rel="alternate"/><published>2021-08-15T12:35:52.062000Z</published><updated>2021-08-15T12:35:52.062000Z</updated><author><name>lior</name><uri>https://forge.codesys.com/u/lior/</uri></author><id>https://forge.codesys.comc19ed70ba55d0c905de60e50b9ca46faad38ea51</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Can I use it like:&lt;br/&gt;
TYPE &lt;strong&gt;Convert_2_int_to_byte&lt;/strong&gt; :UNION&lt;/p&gt;
&lt;p&gt;i: WORD;&lt;br/&gt;
 c:WORD;&lt;br/&gt;
bytes: ARRAY &lt;span&gt;[0..3]&lt;/span&gt; OF BYTE;&lt;/p&gt;
&lt;p&gt;END_UNION&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;TYPE &lt;strong&gt;Convert_Real_to_byte&lt;/strong&gt; :UNION&lt;/p&gt;
&lt;p&gt;a:REAL;&lt;br/&gt;
bytes: ARRAY &lt;span&gt;[0..3]&lt;/span&gt; OF BYTE;&lt;/p&gt;
&lt;p&gt;END_UNION&lt;br/&gt;
END_TYPE&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=25#f878/0794/d2d6/0fb7" rel="alternate"/><published>2021-08-15T12:32:01.319000Z</published><updated>2021-08-15T12:32:01.319000Z</updated><author><name>Ingo</name><uri>https://forge.codesys.com/u/ingo/</uri></author><id>https://forge.codesys.com872e485d4d22dd2ba1ed91b904c4d17d912bfca9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;With an implicite 32 bit intermediate value:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;real3 := TO_REAL(SHL(int2, 16) OR int1);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And if you want to make it very explicit:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;dword4 := SHL(int2, 16);&lt;/span&gt;
&lt;span class="err"&gt;dword4 := dword4 OR int1;&lt;/span&gt;
&lt;span class="err"&gt;real3 := TO_REAL(dword4);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=25#f878/0794/d2d6" rel="alternate"/><published>2021-08-15T12:21:12.294000Z</published><updated>2021-08-15T12:21:12.294000Z</updated><author><name>lior</name><uri>https://forge.codesys.com/u/lior/</uri></author><id>https://forge.codesys.com96a820804db08c0ee62eeed8eb73460974306c2c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have 2 different variable data types INT : 2 Bytes from the first var =INTA and 2 Bytes from the second var=INTB, and &lt;strong&gt;GLUE&lt;/strong&gt; them to REALC-float&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Convert 2 diff type of int to real type</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/2ea25644e8/?limit=25#f878" rel="alternate"/><published>2021-08-15T10:05:16.356000Z</published><updated>2021-08-15T10:05:16.356000Z</updated><author><name>lior</name><uri>https://forge.codesys.com/u/lior/</uri></author><id>https://forge.codesys.com7abfba9c972bd4f1e638c6118827c4f6feca570f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;br/&gt;
I want to convert &lt;strong&gt;2&lt;/strong&gt; diff &lt;strong&gt;INT&lt;/strong&gt; datatype TO &lt;strong&gt;1&lt;/strong&gt; &lt;strong&gt;Real&lt;/strong&gt; datatype.&lt;br/&gt;
for example:&lt;br/&gt;
int1: int &lt;br/&gt;
int2:int&lt;br/&gt;
real3:real&lt;br/&gt;
How Can convert int1&amp;amp;int2 TO Real3?&lt;br/&gt;
Thanks&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>