<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/</id><updated>2021-01-10T16:01:18.469000Z</updated><subtitle>Recent posts to CODESYS bit count in a word</subtitle><entry><title>CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/?limit=25#0ee7" rel="alternate"/><published>2021-01-10T16:01:18.469000Z</published><updated>2021-01-10T16:01:18.469000Z</updated><author><name>wollvieh</name><uri>https://forge.codesys.com/u/wollvieh/</uri></author><id>https://forge.codesys.com09c90003bf858509d297edc64d32751c5ab4aa16</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;How about that  ...&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/?limit=25#a75f/3af7" rel="alternate"/><published>2021-01-10T15:18:48.875000Z</published><updated>2021-01-10T15:18:48.875000Z</updated><author><name>sgronchi</name><uri>https://forge.codesys.com/u/sgronchi/</uri></author><id>https://forge.codesys.com3843116e558fd1c1bacec64ff0858b4604f70ba3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a href="https://help.codesys.com/webapp/_cds_operands_variables_accessing_bits;product=codesys;version=3.5.15.0" rel="nofollow"&gt;https://help.codesys.com/webapp/_cds_operands_variables_accessing_bits;product=codesys;version=3.5.15.0&lt;/a&gt;&lt;br/&gt;
The index must be a constant.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/?limit=250#a75f" rel="alternate"/><published>2021-01-09T17:14:57.524000Z</published><updated>2021-01-09T17:14:57.524000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com7863eac9ee5ed3ae6b538f3b82dfe428cc9ccbc3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The following is pseudocode, don't take it too literal allthough I guess it will probably run ;-)&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c"&gt;(* DECLARATION *)&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
    &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;Bitcount&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;INT&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;CurBoolVal&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;TheWordIWantToCheck&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;WORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="c"&gt;(* CODE *)&lt;/span&gt;
&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;SIZE_OF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;TheWordIWantToCheck&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c"&gt;(* dependends on processor memory width but I assume 16 for now *)&lt;/span&gt;
&lt;span class="n"&gt;FOR&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;TO&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;DO&lt;/span&gt; &lt;span class="c"&gt;(* eg. count bit 0 to 15 *)&lt;/span&gt;
    &lt;span class="n"&gt;CurBoolVal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;TheWordIWantToCheck&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;  &lt;span class="c"&gt;(* Helper to cast Bit to Bool *)&lt;/span&gt;
    &lt;span class="n"&gt;BitCount&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;BitCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;BOOL_TO_INT&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CurBoolVal&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c"&gt;(* cast Bit to Bool *)&lt;/span&gt;
&lt;span class="n"&gt;END_FOR&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;(* after this loop has ended, BitCount will contain the counted bits that are TRUE in the word *)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/?limit=25#17ac" rel="alternate"/><published>2021-01-09T16:42:57.265000Z</published><updated>2021-01-09T16:42:57.265000Z</updated><author><name>wollvieh</name><uri>https://forge.codesys.com/u/wollvieh/</uri></author><id>https://forge.codesys.comfd0b7afc09a839e66f4d2c6336a2dc9b26a9820d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Do yo know the Bitoperator, for examaple Byte.0, Byte.1, or Word.0... Word.15 ? You could build a loop and,  depending on the state of the Bitstate, count the state of the Bits. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>CODESYS bit count in a word</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/9ad62662d6/?limit=25#3815" rel="alternate"/><published>2021-01-09T12:36:15.825000Z</published><updated>2021-01-09T12:36:15.825000Z</updated><author><name>mlepine</name><uri>https://forge.codesys.com/u/mlepine/</uri></author><id>https://forge.codesys.com99a84e67a2c42bdb06ce8f23c9291c9f40c32f9e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Every body,&lt;/p&gt;
&lt;p&gt;I'm pretty new here and i'm trying to put in place a function that will count the number of bit that are SET in a word or a Dword.&lt;/p&gt;
&lt;p&gt;Could some body help me ?&lt;/p&gt;
&lt;p&gt;Thk in advance&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>