<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" 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:atom="http://www.w3.org/2005/Atom"><channel><title>unexpected behavior with bitwise-NOT operator in if() statement</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50486/unexpected-behavior-with-bitwise-not-operator-in-if-statement</link><description>I ran across something unexpected during development on our custom board today. 
 I checked the behavior on an nRF52840-Preview-DK board and was able to reproduce it: 
 This is the very simple code to reproduce the issue: 
 
 All of the if() statements</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Aug 2019 07:45:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50486/unexpected-behavior-with-bitwise-not-operator-in-if-statement" /><item><title>RE: unexpected behavior with bitwise-NOT operator in if() statement</title><link>https://devzone.nordicsemi.com/thread/201759?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 07:45:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49172008-c5d5-4e05-ad46-18c3037694dc</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;you have declared your variables as uint8_t. As our CPU is 32-bit, all operations are performed with 32-bit values, and 8-bit variables are extended to 32 bits. In first three cases, 32-bit (~b) gives 0xffffff0d that is != 0x0d. In last case, result is shrinked to 8 bits to fit into 8-bit variable c, and result of comparison is false (0x0d == 0x0d).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>