<?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: Limitation Of HexToNumber() in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43767#M25292</link>
    <description>&lt;P&gt;JMP 10 has some limitations; it looks like the strings of hex digits in JMP 10 need to be an even number of hex characters. The function above seems to work in JMP 10 (do your own testing!), but the test harness is using features from later releases.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2017 15:02:46 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2017-08-29T15:02:46Z</dc:date>
    <item>
      <title>Limitation Of HexToNumber()</title>
      <link>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43553#M25203</link>
      <description>&lt;P&gt;I'm using JMP10 and notice for Hex To Number( hextext), hextext is limited to 31-bits. Is there a way around this?&lt;/P&gt;&lt;P&gt;Hex To Number("7FFFFFFF") = 2147483647,&amp;nbsp;&lt;SPAN&gt;Hex To Number("&lt;/SPAN&gt;&lt;SPAN&gt;80000000&lt;/SPAN&gt;&lt;SPAN&gt;") = -2147483648.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I need to multiply two hex strings (each can be upto 4-bytes) and in the resulting number, depending on state of MSB bit, extract Bits[29:14] or Bits [27:12]. Can this be done in JSL?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 22:05:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43553#M25203</guid>
      <dc:creator>ravi_sasjmp</dc:creator>
      <dc:date>2017-08-23T22:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Limitation Of HexToNumber()</title>
      <link>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43581#M25215</link>
      <description>&lt;P&gt;JMP uses &lt;A href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format" target="_blank"&gt;64 bit floating point&lt;/A&gt; to represent the JSL numbers; the number of fraction bits available is only 52 or 53. If you multiply two 32 bit integers, you might need 64 bits to represent the answer. If the answer is greater than 52 or 53 bits, you'll lose precision on the low order bits...maybe as many as 11 or 12 bits can be lost.&lt;/P&gt;
&lt;P&gt;Here's some JSL that might help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// crude unsigned hex multiply, poorly tested, no idea what negative numbers are
// do your own testing to make sure this meets your needs
// expects upper case hex ABCDEF, not abcdef
hextonum = [
"0"=&amp;gt;0,"1"=&amp;gt;1,"2"=&amp;gt;2,"3"=&amp;gt;3,
"4"=&amp;gt;4,"5"=&amp;gt;5,"6"=&amp;gt;6,"7"=&amp;gt;7,
"8"=&amp;gt;8,"9"=&amp;gt;9,"A"=&amp;gt;10,"B"=&amp;gt;11,
"C"=&amp;gt;12,"D"=&amp;gt;13,"E"=&amp;gt;14,"F"=&amp;gt;15	
];
numtohex = Associative Array( hextonum &amp;lt;&amp;lt; getvalues, hextonum &amp;lt;&amp;lt; getkeys );

hexmultiply = Function( {a, b}, // "123AE" and "EF012" for example
    {// locals
    ia,  na=length(a),amat = J( na, 1, 0 ), ib,nb=length(b), bmat = J( nb, 1, 0 ),ir,nr=na+nb,result = J( nr+1, 1, 0 ),r="", carry,remainder},
    a = Reverse( a );
    For( ia = 1, ia &amp;lt;= na, ia++,
        amat[ia] = hextonum[Substr( a, ia, 1 )]
    );
    b = Reverse( b );
    For( ib = 1, ib &amp;lt;= nb, ib++,
        bmat[ib] = hextonum[Substr( b, ib, 1 )]
    );
    for(ia=1,ia&amp;lt;=na,ia+=1,
    	for(ib=1,ib&amp;lt;=nb,ib+=1, // this inner loop might speed up by replacing it with matrix math
            result[ia+ib-1] += amat[ia]*bmat[ib];
    	)
    );
    for(ir=1,ir&amp;lt;=nr,ir++, // do the carry. doing it last is fast, but places some sort of a limit on the total length
        remainder = mod(result[ir],16); 
        carry = floor(result[ir]/16); 
        result[ir] = remainder;
        result[ir+1] += carry;
    	r =  numtohex[result[ir]] || r; // build hex result
    );
    r // return value
);

// example hexmultiply
show( hextonumber(hexmultiply("AE2","3B75")));
show( hextonumber("AE2")*hextonumber("3B75"));

// test code...
ntests=0;
start = tickseconds();
For( num1 = 0, num1 &amp;lt; 2e9, num1 = Floor( num1 * 1.07 + 1 ),
    For( num2 = 0, num2 &amp;lt; 2e9, num2 = Floor( num2 * 1.05 + 1 ),
        If( num1 * num2 &amp;gt; 2 ^ 53,
            Continue(); // because double multiply gets wrong answer
        );
        ntests+=1;
        t1 = hexmultiply( Hex( num1, "integer" ), Hex( num2, "integer" ) );
        If( Hex To Number( Substr( t1, 2 ) ) != num1 * num2,
            Show( num1, num2, t1, Hex To Number( Substr( t1, 2 ) ), num1 * num2 )
        );
    )
);
stop=tickseconds();
show(ntests,stop-start,ntests/(stop-start));

// long test...no promises here...this is not a meaningful test...
show( hexmultiply("00123456789ABCDEF0","00200000000000000000000000000000000000"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 13:18:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43581#M25215</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2017-08-24T13:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Limitation Of HexToNumber()</title>
      <link>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43767#M25292</link>
      <description>&lt;P&gt;JMP 10 has some limitations; it looks like the strings of hex digits in JMP 10 need to be an even number of hex characters. The function above seems to work in JMP 10 (do your own testing!), but the test harness is using features from later releases.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2017 15:02:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Limitation-Of-HexToNumber/m-p/43767#M25292</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2017-08-29T15:02:46Z</dc:date>
    </item>
  </channel>
</rss>

