<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Integer type to byte array</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/</id><updated>2020-02-27T13:49:29.386000Z</updated><subtitle>Recent posts to Integer type to byte array</subtitle><entry><title>Integer type to byte array</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/?limit=25#3cd9" rel="alternate"/><published>2020-02-27T13:49:29.386000Z</published><updated>2020-02-27T13:49:29.386000Z</updated><author><name>learnetk</name><uri>https://forge.codesys.com/u/learnetk/</uri></author><id>https://forge.codesys.com70a4f8b699946391b3ec7a4035c30dbba0499810</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Actually in older Codesys you Need to activate the Proffesinal Feature to find Union.&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: Union.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=1442"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: feature.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=1441"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Integer type to byte array</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/?limit=25#530e" rel="alternate"/><published>2020-02-27T13:49:29.285000Z</published><updated>2020-02-27T13:49:29.285000Z</updated><author><name>esse</name><uri>https://forge.codesys.com/u/esse/</uri></author><id>https://forge.codesys.com3d7c3ba5f12ad12a6c02b9424cb5860ce7a27672</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you very much for your reply, if I write this code I receive an error about UNION, is it a codesys code?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Integer type to byte array</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/?limit=25#8fd2" rel="alternate"/><published>2020-02-27T13:49:29.136000Z</published><updated>2020-02-27T13:49:29.136000Z</updated><author><name>ndzied1</name><uri>https://forge.codesys.com/u/ndzied1/</uri></author><id>https://forge.codesys.comb2a11ecbb165cecb666d70a2f40d648844197ee0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;An INT is only 2 Bytes Long.  There are several ways to achieve this.&lt;/p&gt;
&lt;p&gt;One is to create a union with an INT and an array of BYTES&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;TYPE&lt;/span&gt; &lt;span class="nt"&gt;TwoByte&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;UNION&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;i&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;bytes&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;ARRAY&lt;/span&gt; &lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="nx"&gt;..2&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;BYTE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="nt"&gt;END_UNION&lt;/span&gt;
&lt;span class="nt"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you create a variable:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyVar&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;TwoByte&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then you can copy the integer into &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyVar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then the two bytes that make up that integer will be available at:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyVar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;MyVar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Integer type to byte array</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/6b5d3bfae1/?limit=25#3b82" rel="alternate"/><published>2020-02-27T13:49:29.041000Z</published><updated>2020-02-27T13:49:29.041000Z</updated><author><name>esse</name><uri>https://forge.codesys.com/u/esse/</uri></author><id>https://forge.codesys.comd701276e217bcb23fc8e6d0c1efe3374992788ae</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello, another question from a Codesys newbie, is a possible way to convert an integer value to a byte array,for example i try to make a program that the user will insert a value such 567 and i want to convert it to 4 bytes&lt;br/&gt;
Thank you in advance &lt;/p&gt;&lt;/div&gt;</summary></entry></feed>