<?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: How does one perform Bitwise operations in JMP formulas? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737570#M91873</link>
    <description>&lt;P&gt;hm ...&lt;BR /&gt;I added a request to the wishlist:&amp;nbsp;&lt;LI-MESSAGE title="JSL bit operations" uid="724448" url="https://community.jmp.com/t5/JMP-Wish-List/JSL-bit-operations/m-p/724448#U724448" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;(&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;already requested in 2020)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now, (Jmp18), what is the fastest way to extract the 32 bits of a 32bit number?&lt;/P&gt;&lt;P&gt;... for 10 mio rows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;n_rows = 100000;
dt = New Table( "test", Add Rows( n_rows ), New Column( "rand int", Set each value( Random Integer( 0, 4294967295 ) ) ) );

checkBit = Function( {x, bit},
	(Mod( Floor( x / 2 ^ (0 + bit) ), 2 ) == 1)
);


t0 = HP Time();
For( i = 1, i &amp;lt;= 32, i++,
	dt &amp;lt;&amp;lt; New Column( "bit" || Char(i), Set each value( checkBit( :rand int, i ) ) )
);
Show( (HP Time() - t0) / 1000000 ); // references

//BITS:NUMTOBITS from https://community.jmp.com/t5/Uncharted/7-things-to-know-about-Twitter/ba-p/21000
// faster
getBits = Function( {x},
	{result = {}, i},
	For( i = 4294967296 / 2, i &amp;gt;= 1, i /= 2,
		Insert Into(
			result,
			If( x &amp;gt;= i,
				x = x - i;
				1;
			,
				0
			)
		)
	);
	Transpose(Matrix(result));
);

// ~ factor 10 faster
getBits = Function( {x},
Transpose(Matrix(Transform Each({bit}, Words(Hex( x, Base( 2 ), Pad To( 32 ) ),""),Num(bit))));
);

//getBits(4294967295);

For( i = 1, i &amp;lt;= 32, i++,
	New Column( "bit" || Char( i ) )
);

t0 = HP Time();
mat = J( n_rows, 32, 0 );
For( myrow = 1, myrow &amp;lt;= n_rows, myrow++,
	mat[myrow, 0] = getBits( :rand int[myrow] )
);

dt[0, N Cols( dt ) - 31 :: N Cols( dt )] = mat;
Show( (HP Time() - t0) / 1000000 );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Mar 2024 08:22:11 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2024-03-22T08:22:11Z</dc:date>
    <item>
      <title>How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/353793#M60343</link>
      <description>&lt;P&gt;Hi, I imagine this is simply an issue in which I am not finding the correct formula option but how does one perform basic bitwise operations in a JMP formula?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g. Here's an example Python example that I would like to replicate in JMP: &lt;STRONG&gt;lambda x: ((((x&amp;gt;&amp;gt;1)&amp;amp;0x1))&amp;lt;&amp;lt;2)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks, Ross&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:25:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/353793#M60343</guid>
      <dc:creator>docrossus</dc:creator>
      <dc:date>2023-06-10T23:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/353812#M60344</link>
      <description>&lt;P&gt;JMP has no native bitwise operators. In your example, I'd try this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// untested code for  (((x&amp;gt;&amp;gt;1)&amp;amp;0x1))&amp;lt;&amp;lt;2
f = function( { x },
    ( mod( floor( x / 2 ), 2 ) == 1 ) * 4
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;x&amp;gt;&amp;gt;1 (right shift 1) divides x by 2, &amp;amp;1 keeps only the least bit (zero/one, even/odd), and &amp;lt;&amp;lt;2 (left shift 2) multiplies by 4. (Assuming python works like C and I haven't forgotten...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have a lot of these, with peculiar bit positions, etc, you might want to look for a bit manipulation library. The only one I'm aware of is in&amp;nbsp;&lt;LI-MESSAGE title="7 things to know about Twitter" uid="21000" url="https://community.jmp.com/t5/Uncharted/7-things-to-know-about-Twitter/m-p/21000#U21000" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;and may not be very friendly (BITS.jsl file in the zip file). I don't remember exactly what it does, but it looks like it is solving the problem by turning a number into a character string of 32 ones and zeros, then combining the strings using AND/OR/etc logic rules. It is probably missing any operations that were not needed. And I'm pretty sure the HTTPRequest function would make that code much easier now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Negative numbers can be really weird when doing right shifts. The sign bit can be trouble.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 02:26:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/353812#M60344</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-01-29T02:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737570#M91873</link>
      <description>&lt;P&gt;hm ...&lt;BR /&gt;I added a request to the wishlist:&amp;nbsp;&lt;LI-MESSAGE title="JSL bit operations" uid="724448" url="https://community.jmp.com/t5/JMP-Wish-List/JSL-bit-operations/m-p/724448#U724448" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;BR /&gt;(&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;already requested in 2020)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now, (Jmp18), what is the fastest way to extract the 32 bits of a 32bit number?&lt;/P&gt;&lt;P&gt;... for 10 mio rows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;n_rows = 100000;
dt = New Table( "test", Add Rows( n_rows ), New Column( "rand int", Set each value( Random Integer( 0, 4294967295 ) ) ) );

checkBit = Function( {x, bit},
	(Mod( Floor( x / 2 ^ (0 + bit) ), 2 ) == 1)
);


t0 = HP Time();
For( i = 1, i &amp;lt;= 32, i++,
	dt &amp;lt;&amp;lt; New Column( "bit" || Char(i), Set each value( checkBit( :rand int, i ) ) )
);
Show( (HP Time() - t0) / 1000000 ); // references

//BITS:NUMTOBITS from https://community.jmp.com/t5/Uncharted/7-things-to-know-about-Twitter/ba-p/21000
// faster
getBits = Function( {x},
	{result = {}, i},
	For( i = 4294967296 / 2, i &amp;gt;= 1, i /= 2,
		Insert Into(
			result,
			If( x &amp;gt;= i,
				x = x - i;
				1;
			,
				0
			)
		)
	);
	Transpose(Matrix(result));
);

// ~ factor 10 faster
getBits = Function( {x},
Transpose(Matrix(Transform Each({bit}, Words(Hex( x, Base( 2 ), Pad To( 32 ) ),""),Num(bit))));
);

//getBits(4294967295);

For( i = 1, i &amp;lt;= 32, i++,
	New Column( "bit" || Char( i ) )
);

t0 = HP Time();
mat = J( n_rows, 32, 0 );
For( myrow = 1, myrow &amp;lt;= n_rows, myrow++,
	mat[myrow, 0] = getBits( :rand int[myrow] )
);

dt[0, N Cols( dt ) - 31 :: N Cols( dt )] = mat;
Show( (HP Time() - t0) / 1000000 );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2024 08:22:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737570#M91873</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-03-22T08:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737625#M91883</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;n_rows = 100000;
dt = New Table( "test", Add Rows( n_rows ), New Column( "rand int", Set each value( Random Integer( 0, 4294967295 ) ) ) );

t0 = HP Time();
data = dt[0, 1];
For( i = 1, i &amp;lt;= 32, i++,
	dt &amp;lt;&amp;lt; New Column( "bit" || Char( i ) );
	dt[0,i + 1] = Mod( data, 2 );
	data = Floor( data / 2 );
);
Show( (HP Time() - t0) / 1000000 ); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This moves most of the looping into C++ code. If you can figure out how to do it with one divide, you might speed it up some more. You might want to use b0 rather than b1 for the least significant bit's name so its value is 2^0==1. Depends what the bits represent.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 11:06:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737625#M91883</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2024-03-22T11:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737641#M91886</link>
      <description>&lt;P&gt;wow, great :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 11:55:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/737641#M91886</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-03-22T11:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/772617#M95310</link>
      <description>&lt;P&gt;JMP Developers:&lt;BR /&gt;&lt;BR /&gt;Please, please, please, please, please add bitwise operators to JSL.&amp;nbsp; Analyzing log files with bit fields (like error bits, status bits, etc.), I have had so many occasions to utilize bitwise operators.&amp;nbsp; This feature can also be extended by making user-defined bit mappings an option in the column properties (i.e. bit 0 = door open, bit1 = door closed, ...) and then in graph builder,&amp;nbsp;plotting a single bit-mapped column variable against time, you could show all of the bit states flipping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 22:16:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/772617#M95310</guid>
      <dc:creator>BetaTreeCamel91</dc:creator>
      <dc:date>2024-07-11T22:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: How does one perform Bitwise operations in JMP formulas?</title>
      <link>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/772618#M95311</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/40195"&gt;@BetaTreeCamel91&lt;/a&gt;&amp;nbsp;, did you vote ?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;LI-MESSAGE title="JSL bit operations" uid="724448" url="https://community.jmp.com/t5/JMP-Wish-List/JSL-bit-operations/m-p/724448#U724448" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 22:18:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-does-one-perform-Bitwise-operations-in-JMP-formulas/m-p/772618#M95311</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2024-07-11T22:18:42Z</dc:date>
    </item>
  </channel>
</rss>

