<?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 Trying to Check if a number is in Binary format in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604124#M80706</link>
    <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to write a script that takes an input and encrypts it with a cipher. In order to do that, the input text has to be in binary. I asked ChatGPT for help and it recommende&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if ( Matches Reg Expr(input, "^[01]+$"),
     Show("Valid"),
     Show("Not Valid"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;That doesn't work, and I'm trying to figure out why. I'm also trying to figure out a way to check if a number is in binary, so any help would be greatly appreciated&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jun 2023 16:33:54 GMT</pubDate>
    <dc:creator>LatentHyena653</dc:creator>
    <dc:date>2023-06-08T16:33:54Z</dc:date>
    <item>
      <title>Trying to Check if a number is in Binary format</title>
      <link>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604124#M80706</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to write a script that takes an input and encrypts it with a cipher. In order to do that, the input text has to be in binary. I asked ChatGPT for help and it recommende&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;if ( Matches Reg Expr(input, "^[01]+$"),
     Show("Valid"),
     Show("Not Valid"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;That doesn't work, and I'm trying to figure out why. I'm also trying to figure out a way to check if a number is in binary, so any help would be greatly appreciated&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:33:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604124#M80706</guid>
      <dc:creator>LatentHyena653</dc:creator>
      <dc:date>2023-06-08T16:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Check if a number is in Binary format</title>
      <link>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604195#M80708</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	If(	//If the string only contains 0 and 1 and is at least 1 character long
		!is missing(regex( input, "^[01]+$" ))
	,	//then return 1
		isbinary= 1
	,	//otherwise return 0
		isbinary=0
	);
	return(isbinary);
);

CheckIfBinary("123");
CheckIfBinary("10");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2023 22:21:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604195#M80708</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2023-02-22T22:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Check if a number is in Binary format</title>
      <link>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604493#M80725</link>
      <description>&lt;P&gt;Lost a line at the top:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;CheckIfBinary = Function( {input},
	{isbinary},
	If( 	//If the string only contains 0 and 1 and is at least 1 character long
		!Is Missing( Regex( input, "^[01]+$" ) )
	, 	//then return 1
		isbinary = 1
	, 	//otherwise return 0
		isbinary = 0
	);
	Return( isbinary );
);

CheckIfBinary( "123" );
CheckIfBinary( "10" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I've avoided ChatGPT's auto complete until just now. That's interesting...it found the right regex anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/46798"&gt;@LatentHyena653&lt;/a&gt; - JMP's regex returns a missing value for "no match" and the text of the match otherwise. Missing value testing must be done with the isMissing function. Most other languages will have different details for using regex, so it isn't too surprising.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, JMP has a hex() function that will convert text to a hex string:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;hexData = hex("ABC");
binaryData = substitute(hexData,
	"0","0000",
	"1","0001",
	"2","0010",
	"3","0011",
	"4","0100",
	"5","0101",
	"6","0110",
	"7","0111",
	"8","1000",
	"9","1001",
	"A","1010",
	"B","1011",
	"C","1100",
	"D","1101",
	"E","1110",
	"F","1111",
	"????"
);
show(hexData,binaryData);
// hexData = "414243";
// binaryData = "010000010100001001000011";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And, as shown, substitute() can convert the hex string to a binary string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, notice that the binary string of 1s and 0s is actually a character string representation of binary data. JMP also has a blob data type if you need to work with actual binary data. But it is a lot easier to work with printable 1s and 0s.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 14:58:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604493#M80725</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-02-23T14:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Check if a number is in Binary format</title>
      <link>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604501#M80726</link>
      <description>&lt;P&gt;Thank you for catching that&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Feb 2023 15:06:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Trying-to-Check-if-a-number-is-in-Binary-format/m-p/604501#M80726</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2023-02-23T15:06:40Z</dc:date>
    </item>
  </channel>
</rss>

