<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Lothar Miller - Graycode</title>
    <link>http://www.lothar-miller.de/s9y/</link>
    <description>Elektronik und Musik</description>
    <dc:language>de</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Wed, 20 Apr 2011 06:47:51 GMT</pubDate>

    <image>
        <url>http://www.lothar-miller.de/s9y/templates/bulletproof/img/s9y_banner_small.png</url>
        <title>RSS: Lothar Miller - Graycode - Elektronik und Musik</title>
        <link>http://www.lothar-miller.de/s9y/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Graycode Umwandlung</title>
    <link>http://www.lothar-miller.de/s9y/archives/69-Graycode-Umwandlung.html</link>
            <category>Graycode</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/69-Graycode-Umwandlung.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=69</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=2.0&amp;type=comments&amp;cid=69</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Hier finden sich C-Routinen zur Umwandlung von Graycode nach Binärcode und umgekehrt. Das Ganze basiert auf dem VHDL-Code hier: &lt;a title=&quot;Graycode VHDL&quot; target=&quot;_blank&quot; href=&quot;http://www.lothar-miller.de/s9y/archives/68-Graycode-Umwandlung.html&quot;&gt;Graycode-Umwandlung in VHDL&lt;/a&gt;&lt;/p&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;The purpose of this function is to convert an unsigned&lt;br /&gt;binary number to reflected binary Gray code.&lt;br /&gt;Binary 1-x-0-x-1-x-0-x-1&lt;br /&gt;       |  `   `   `   ` &lt;br /&gt;       |   |   |   |   |       x = xor&lt;br /&gt;       v   v   v   v   v       Abarbeitung MSB ... LSB &lt;br /&gt;Gray   1   1   0   0   1&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; BinaryToGray(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; (num&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) ^ num;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;A tricky trick: for up to 2^n bits, you can convert Gray to binary by&lt;br /&gt;performing (2^n) - 1 binary-to Gray conversions. All you need is the&lt;br /&gt;function above and a &#039;for&#039; loop.&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinary(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int&lt;/span&gt; i;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;for&lt;/span&gt; (i=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;15&lt;/span&gt;; i++) temp = BinaryToGray(temp);&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;Gray   1   0   1   0   1&lt;br /&gt;       |  /   /   /   / &lt;br /&gt;       | x   x   x   x     x = xor&lt;br /&gt;       v/ `v/ `v/ `v/ `v   Abarbeitung MSB ... LSB &lt;br /&gt;Binary 1   1   0   0   1   &lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinaryX(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int&lt;/span&gt; i;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  temp &amp;amp;= &lt;span style=&quot;color: rgb(0, 85, 136); font-weight: bold;&quot;&gt;0x8000&lt;/span&gt;;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;for&lt;/span&gt; (i=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;14&lt;/span&gt;; i&amp;gt;=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;; i--) {&lt;br /&gt;     &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; ( (!!(temp&amp;amp;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;(i+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;)))) != (!!(num&amp;amp;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i))) )&lt;br /&gt;        temp |= (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i);&lt;br /&gt;  }&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;The purpose of this function is to convert a reflected binary&lt;br /&gt;Gray code number to a binary number.&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinaryPow2(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;4&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;);&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;/pre&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;p&gt;Die Grundlagen dieser Umwandlungsroutinen sind auf &lt;a href=&quot;http://www.wisc-online.com/ViewObject.aspx?ID=IAU8307&quot; target=&quot;_blank&quot; title=&quot;Basics Graycode-Umwandlung&quot;&gt;www.wisc-online.com&lt;/a&gt; schön erklärt.&lt;/p&gt;

 
    </content:encoded>

    <pubDate>Sun, 17 Jan 2010 19:07:00 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/69-guid.html</guid>
    
</item>

</channel>
</rss>
