<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Configuring a 2's compliment </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/</id><updated>2024-09-28T11:28:21.440000Z</updated><subtitle>Recent posts to Configuring a 2's compliment </subtitle><entry><title>Configuring a 2's compliment </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/?limit=25#9305" rel="alternate"/><published>2024-09-28T11:28:21.440000Z</published><updated>2024-09-28T11:28:21.440000Z</updated><author><name>TimvH</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.coma009a88d34529e38d587828f576f85efe28104d3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;You could create a DUT of the Type Union and add an array of 2 bytes + an Int.&lt;br/&gt;
Then write the byte values in the array of the Union and read the Int.&lt;/p&gt;
&lt;p&gt;Or&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="kr"&gt;VAR&lt;/span&gt;
    &lt;span class="n"&gt;iInt&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;byHigh&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;BYTE&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;1111&lt;/span&gt;&lt;span class="n"&gt;_1111&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;byLow&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;BYTE&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;1111&lt;/span&gt;&lt;span class="n"&gt;_1111&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nv"&gt;iInt&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;TO_INT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;byHigh&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;byLow&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</summary></entry><entry><title>Configuring a 2's compliment </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/?limit=25#2ee9" rel="alternate"/><published>2024-09-27T11:25:21.280000Z</published><updated>2024-09-27T11:25:21.280000Z</updated><author><name>liamb</name><uri>https://forge.codesys.com/u/liamb/</uri></author><id>https://forge.codesys.com60416db98f393b5e649dc768eb1643f0c746acb2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi, did you end up finding a way to take 2's compliment?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Configuring a 2's compliment </title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/3f0e4fc418/?limit=25#d8da" rel="alternate"/><published>2021-11-29T18:08:56.412000Z</published><updated>2021-11-29T18:08:56.412000Z</updated><author><name>vvora</name><uri>https://forge.codesys.com/u/vvora/</uri></author><id>https://forge.codesys.com2ab151e03c159ec7d541f117ec25c4f9937f68a3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;I have an array of Bytes reading different messages from a COB-ID, one of them is a 16 bit signed INT, 2's compliment and other one is  16 bit unsigned INT, 2's compliment. What would be the best way to read them. Any function block for conversion? I assume I will have to take 2's compliment of the data read? &lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>