[haiku-development] Re: Question about |=

  • From: Philippe Saint-Pierre <stpere@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 11 Aug 2012 17:34:12 -0400

Hi,

> But what will fScanMode show?
>
> int fScanMode |= 2;
>
> Taken from this
>
>                         fScanMode = 0;
>
>                         if (fDiscoverable->Value()) {
>                                 fScanMode = 1;
>                                 fVisible->SetEnabled(true);
>                         } else {
>                                 fVisible->SetValue(false);
>                                 fVisible->SetEnabled(false);
>                         }
>
>                         if (fVisible->Value())
>                                 fScanMode |= 2;

Imagine fScanMode is worth 1, in binary that would be 00000001, that
operator is equivalent to fScanMode = fScanMode | 2.  Now 2 is
00000010, so the operation will give that fScanMode == 00000011.  Is
that answering your question? :)  In essence, it is setting the second
bit in 'less significant order' to 1.

--
Philippe

Other related posts: