<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issue with Bitwise NOT (BNOT()) Function Result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876060#M346147</link>
    <description>&lt;P&gt;This is quite strange that we are getting these numbers but when using other functions like BAND we get a decimal number instead of a binary number.&lt;/P&gt;&lt;P&gt;Even in other programming languages like Python or C/C++ we get a number instead of binary digits or some random numbers in output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;PRE&gt;595  data _null_;
596    ____x=0;
597    bnotx = BNOT(____x);
598
599    put ____x= binary64.;
600    put bnotx= binary64.;
601  run;

&lt;STRONG&gt;____x=0000000000000000000000000000000000000000000000000000000000000000
bnotx=0100000111101111111111111111111111111111111000000000000000000000&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


602  data _null_;
603    ____x=1;
604    bnotx = BNOT(____x);
605
606    put ____x= binary64.;
607    put bnotx= binary64.;
608  run;

&lt;STRONG&gt;____x=0011111111110000000000000000000000000000000000000000000000000000
bnotx=0100000111101111111111111111111111111111110000000000000000000000&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;Is there any way to convert these binary numbers back to 0 or 1 when using BNOT()&lt;/P&gt;</description>
    <pubDate>Tue, 16 May 2023 17:42:22 GMT</pubDate>
    <dc:creator>vijaypratap0195</dc:creator>
    <dc:date>2023-05-16T17:42:22Z</dc:date>
    <item>
      <title>Issue with Bitwise NOT (BNOT()) Function Result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876048#M346142</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;I am currently facing an issue with the Bitwise NOT (BNOT) function in my SAS code. Instead of producing the expected inverse of 1 or 0, the function is returning random numbers in the result window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using the BNOT function on binary values 1 and 0, but the output is not as expected. Has anyone encountered a similar problem or have any insights into what might be causing this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help or suggestions would be greatly appreciated. Thank you in advance for your assistance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data Logical_Input;
input x y;
datalines;
0 0
0 1
1 0
1 1
;
run;

OPTION VALIDVARNAME=ANY;
data Logical_operation_table;
set Logical_Input;
"x and y"n	= BAND(x,y);
"x or y"n 	= BOR(x,y);
"x xor y"n 	= BXOR(x,y);
"not x"n 	= BNOT(x);
run;

proc print noobs; run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;x and y&lt;/TD&gt;&lt;TD&gt;x or y&lt;/TD&gt;&lt;TD&gt;x xor y&lt;/TD&gt;&lt;TD&gt;not x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4294967295&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4294967295&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4294967294&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4294967294&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 16:47:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876048#M346142</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-05-16T16:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Bitwise NOT (BNOT()) Function Result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876056#M346145</link>
      <description>&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  ____x=0;
  bnotx = BNOT(____x);

  put ____x= binary64.;
  put bnotx= binary64.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  ____x=1;
  bnotx = BNOT(____x);

  put ____x= binary64.;
  put bnotx= binary64.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and look into the log so you will see which bits are flipped&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 17:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876056#M346145</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-16T17:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Bitwise NOT (BNOT()) Function Result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876060#M346147</link>
      <description>&lt;P&gt;This is quite strange that we are getting these numbers but when using other functions like BAND we get a decimal number instead of a binary number.&lt;/P&gt;&lt;P&gt;Even in other programming languages like Python or C/C++ we get a number instead of binary digits or some random numbers in output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;PRE&gt;595  data _null_;
596    ____x=0;
597    bnotx = BNOT(____x);
598
599    put ____x= binary64.;
600    put bnotx= binary64.;
601  run;

&lt;STRONG&gt;____x=0000000000000000000000000000000000000000000000000000000000000000
bnotx=0100000111101111111111111111111111111111111000000000000000000000&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


602  data _null_;
603    ____x=1;
604    bnotx = BNOT(____x);
605
606    put ____x= binary64.;
607    put bnotx= binary64.;
608  run;

&lt;STRONG&gt;____x=0011111111110000000000000000000000000000000000000000000000000000
bnotx=0100000111101111111111111111111111111111110000000000000000000000&lt;/STRONG&gt;
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;&lt;P&gt;Is there any way to convert these binary numbers back to 0 or 1 when using BNOT()&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 17:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876060#M346147</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-05-16T17:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Bitwise NOT (BNOT()) Function Result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876062#M346149</link>
      <description>&lt;P&gt;SAS has only 1 numerical type: number (take a look here: &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p0dv87zb3bnse6n1mqo360be70qr.htm#:~:text=Although%20there%20are%20various%20ways,adequate%20amount%20of%20numerical%20accuracy.)" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p0dv87zb3bnse6n1mqo360be70qr.htm#:~:text=Although%20there%20are%20various%20ways,adequate%20amount%20of%20numerical%20accuracy.)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and it keeps both integers and floating points in it on 8 bytes (64 bits).&amp;nbsp;C keeps numbers also on 8 bytes but has different types so the same sequence of bits means different things depending on type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Documentation say that bitwise functions operates on numbers in range from 0 to 2^32 - 1, and those numbers are represented by those red bits:&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;bnotx=010000011110&lt;FONT color="#FF0000"&gt;1111111111111111111111111111111&lt;/FONT&gt;000000000000000000000&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT:]&lt;/P&gt;
&lt;P&gt;Also take a look at the log of the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  x=1;
  y=0;
  band = Band(y,x);
  bor  = Bor(y,x);
  bnot = Bnot(y);

  put x binary64. x best32.;
  put y  binary64. y best32.;
  put band binary64. band best32.;
  put bor binary64. bor best32.;
  put bnot binary64. bnot best32.;

  z=2**32 - 1;
  put z=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will see that Bnot(0) is 2^32 - 1, so "full" negation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 18:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876062#M346149</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-16T18:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Bitwise NOT (BNOT()) Function Result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876074#M346158</link>
      <description>&lt;P&gt;What number did you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have binary string 0001 and you flip all of the zeros to ones you get 1110 which is the number 14.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;You do not get 0.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to limit it to fixed number of bits use the MOD() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ndigits=1 ;
bnotx=mod(bnot(x),2**ndigits);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's look at all 16 possible values of 4 binary digits.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do x=0 to 7;
    bnotx=bnot(x);
    bnot4=mod(bnotx,2**4);
    put / (3*x 3*bnotx 3*bnot4) ( binary4. +1 hex8. comma14. /);
  end; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;0000 00000000             0
1111 FFFFFFFF 4,294,967,295
1111 0000000F            15

0001 00000001             1
1110 FFFFFFFE 4,294,967,294
1110 0000000E            14

0010 00000002             2
1101 FFFFFFFD 4,294,967,293
1101 0000000D            13

0011 00000003             3
1100 FFFFFFFC 4,294,967,292
1100 0000000C            12

0100 00000004             4
1011 FFFFFFFB 4,294,967,291
1011 0000000B            11

0101 00000005             5
1010 FFFFFFFA 4,294,967,290
1010 0000000A            10

0110 00000006             6
1001 FFFFFFF9 4,294,967,289
1001 00000009             9

0111 00000007             7
1000 FFFFFFF8 4,294,967,288
1000 00000008             8
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 18:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-Bitwise-NOT-BNOT-Function-Result/m-p/876074#M346158</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T18:31:54Z</dc:date>
    </item>
  </channel>
</rss>

