<?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>Why does this particular flag involve an &amp;quot;or&amp;quot; operation?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17129/why-does-this-particular-flag-involve-an-or-operation</link><description>uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED |
 BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
 
 And then when I look up &amp;quot;BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;&amp;quot;, I got this: 
 (BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Oct 2016 06:45:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17129/why-does-this-particular-flag-involve-an-or-operation" /><item><title>RE: Why does this particular flag involve an "or" operation?</title><link>https://devzone.nordicsemi.com/thread/65737?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2016 06:45:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:780f8039-badd-40ba-8702-ba887f339273</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Please accept one of the answers, to show the case as closed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why does this particular flag involve an "or" operation?</title><link>https://devzone.nordicsemi.com/thread/65738?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2016 03:23:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe532777-0f10-45b0-9a6e-50014db40d90</guid><dc:creator>Mitch996</dc:creator><description>&lt;p&gt;Got it. Much obliged.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why does this particular flag involve an "or" operation?</title><link>https://devzone.nordicsemi.com/thread/65736?ContentTypeID=1</link><pubDate>Tue, 18 Oct 2016 09:18:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:618474f4-dfb4-4d2b-a3de-64f6423f45ec</guid><dc:creator>AmiguelS</dc:creator><description>&lt;p&gt;The OR operator is being used to set multiple bits of that flag in a single line.&lt;/p&gt;
&lt;p&gt;For example, conside you have a flag of 1 byte (8 bits), and each bit controls one feature.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define FEATURE_ONE   0b00000001
#define FEATURE_TWO   0b00000010
#define FEATURE_THREE 0b00000100
#define FEATURE_FOUR  0b00001000
#define FEATURE_FIVE  0b00010000
#define FEATURE_SIX   0b00100000
#define FEATURE_SEVEN 0b01000000
#define FEATURE_EIGHT 0b10000000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And now you wish to turn on features 2 and 5. You can do so with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t flags = FEATURE_TWO | FEATURE_FIVE;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works because when doing an OR of the two numbers, the set bits from each number prevail, so:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    00000010
    00010000
or__________
    00010010
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why does this particular flag involve an "or" operation?</title><link>https://devzone.nordicsemi.com/thread/65740?ContentTypeID=1</link><pubDate>Tue, 18 Oct 2016 06:51:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52f26bfa-ef1e-4dfe-8580-d1dff4849f83</guid><dc:creator>Mitch996</dc:creator><description>&lt;p&gt;I forgot to say that I was reading someone else&amp;#39;s code. If it were me I wouldn&amp;#39;t use the &amp;quot;|&amp;quot; operator like that. My question isn&amp;#39;t with the protocol itself, but on the &amp;quot;|&amp;quot; operator, I&amp;#39;ve seen this use several times before but I didn&amp;#39;t really care why or how until now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why does this particular flag involve an "or" operation?</title><link>https://devzone.nordicsemi.com/thread/65739?ContentTypeID=1</link><pubDate>Tue, 18 Oct 2016 05:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:757bfdc1-182c-4a18-988d-5590ba45aa30</guid><dc:creator>wlgrd</dc:creator><description>&lt;p&gt;I don&amp;#39;t really understand the question, and why you set your &lt;code&gt;flags&lt;/code&gt; like this. If using the &lt;code&gt;LE_ONLY&lt;/code&gt; flag you implicitly also set &lt;code&gt;BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;#define BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE (0x02)&lt;/code&gt; Note that this define does not say LE_&lt;strong&gt;ONLY&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;#define BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE (BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Hence, if you want to set your flag like this, either change it to&lt;/p&gt;
&lt;p&gt;&lt;code&gt;uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;&lt;code&gt;uint8_t flags = BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED)&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>