<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; JScript: Преобразование строки в число]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=2074</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=2074&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «JScript: Преобразование строки в число».]]></description>
		<lastBuildDate>Fri, 21 Oct 2011 09:30:39 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=52774#p52774</link>
			<description><![CDATA[<p>Надеюсь <a href="http://vestikinc.narod.ru/AB/index.htm">это</a> поможет.</p><br /><p>И это тоже.<br /></p><div class="codebox"><pre><code>
function binDec(v, n2){
var n=0, l;
l=v.length;
v=v.split(&quot;&quot;).reverse().join(&quot;&quot;);//вывернуть строку на изнанку
while(l--){n+=v.charAt(l)==1?Math.pow(2, l):0;};
d.getElementById(&quot;dec&quot;).value=intervalNumSp(n, n2);
 };//
//
function binHex(n){
decHex(d.getElementById(&quot;dec&quot;).value, n);
 };//
//
function hexDec(v, n){
var s=intervalNumSp(parseInt(v, 16), n);
d.getElementById(&quot;dec&quot;).value=s;
 };//
//
function hexBin(n){
decBin(d.getElementById(&quot;dec&quot;).value, n);
 };//
//
function decHex(v, n){
var s=intervalNumSp(Number(v).toString(16).toLocaleUpperCase(), n);
d.getElementById(&quot;hex&quot;).value=s;
 };//
//
function decBin(v, n){
var s=intervalNumSp(Number(v).toString(2), n);
d.getElementById(&quot;bin&quot;).value=s;
 };//
//
function intervalNumSp(n1, n2){
var n3;
n1=n1+&quot;&quot;;//на всякий случай, делаем строку, может число пришло
n3=n1.length%n2;//получить старшую не полную часть
n2=new RegExp(&#039;([0-9A-Fa-f]{&#039;+n2+&#039;})&#039;, &quot;g&quot;);
//взять первые символы, 1шт., 2шт., 3шт., а остаток разделить пробелами
n1=n1.substr(0, n3)+n1.substr(n3).replace(n2, &quot; $1&quot;);//перед долларом прбел
return n1.replace(/^ /, &quot;&quot;);//удалить возможный первый пробел
 };//</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Любитель)]]></author>
			<pubDate>Fri, 21 Oct 2011 09:30:39 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=52774#p52774</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=52732#p52732</link>
			<description><![CDATA[<div class="quotebox"><cite>Spy00000 пишет:</cite><blockquote><div class="codebox"><pre><code>parseInt</code></pre></div></blockquote></div><p>Спасибо! Давно не кодил - забыл всё! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (-red-)]]></author>
			<pubDate>Thu, 20 Oct 2011 12:18:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=52732#p52732</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=52673#p52673</link>
			<description><![CDATA[<div class="quotebox"><cite>-red- пишет:</cite><blockquote><p>А как можно преобразовать HEX строку в число?</p></blockquote></div><div class="codebox"><pre><code>var n1 = parseInt( &quot;FFFF&quot; , 16 );
var n2 = parseInt( &quot;0xFFF0&quot; , 16 );
WScript.Echo( &#039;n1 = &#039; + n1 + &#039;,  n2 = &#039; + n2 );</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Spy00000)]]></author>
			<pubDate>Wed, 19 Oct 2011 09:29:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=52673#p52673</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=52662#p52662</link>
			<description><![CDATA[<p>А как можно преобразовать HEX строку в число?</p>]]></description>
			<author><![CDATA[null@example.com (-red-)]]></author>
			<pubDate>Wed, 19 Oct 2011 07:36:27 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=52662#p52662</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=13157#p13157</link>
			<description><![CDATA[<p>А чем плохо неявное преобразование?<br />Например:</p><div class="codebox"><pre><code>var str=&quot;9876543210&quot;;
var num=str*1;

WSH.echo([str,typeof(str)])
WSH.echo([num,typeof(num)])</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (fps)]]></author>
			<pubDate>Mon, 11 Aug 2008 17:59:53 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=13157#p13157</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=13144#p13144</link>
			<description><![CDATA[<p>Спасибо! В справочнике не нашел этого метода :-[</p>]]></description>
			<author><![CDATA[null@example.com (-red-)]]></author>
			<pubDate>Mon, 11 Aug 2008 15:10:50 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=13144#p13144</guid>
		</item>
		<item>
			<title><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=13143#p13143</link>
			<description><![CDATA[<p>А чем parseInt нехорош?<br /></p><div class="quotebox"><blockquote><p><strong>parseInt Method</strong></p><p>Returns an integer converted from a string.</p><p><strong>parseInt(numString, [radix])</strong></p><p>Arguments</p><p>numString&nbsp; Required. A string to convert into a number. </p><p>radix&nbsp; Optional. A value between 2 and 36 indicating the base of the number contained in numString. If not supplied, strings with a prefix of &#039;0x&#039; are considered hexadecimal and strings with a prefix of &#039;0&#039; are considered octal. All other strings are considered decimal.</p></blockquote></div><div class="codebox"><pre><code>n = parseInt(&quot;9876543210&quot;);
WScript.Echo(typeof(n) + &quot;\n&quot; + n);</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 11 Aug 2008 14:11:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=13143#p13143</guid>
		</item>
		<item>
			<title><![CDATA[JScript: Преобразование строки в число]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=13139#p13139</link>
			<description><![CDATA[<p>Для себя решил таким способом, буду рад узнать более красивые/корректные решения.</p><div class="codebox"><pre><code>// file .js
function DECStr2Int(sDigit){
    var iDigit=0;
    var i = sDigit.length;
    if(i &lt;= 0) return null;
    while(i--){
//        WScript.echo(sDigit.charAt(i) +&quot; at &quot;+i.toString() );
        switch (sDigit.charAt(sDigit.length - i-1)){
            case &quot;0&quot;:
                iDigit += 0*Math.pow(10,i);
                break;
            case &quot;1&quot;:
                iDigit += 1*Math.pow(10,i);
                break;
            case &quot;2&quot;:
                iDigit += 2*Math.pow(10,i);
                break;
            case &quot;3&quot;:
                iDigit += 3*Math.pow(10,i);
                break;
            case &quot;4&quot;:
                iDigit += 4*Math.pow(10,i);
                break;
            case &quot;5&quot;:
                iDigit += 5*Math.pow(10,i);
                break;
            case &quot;6&quot;:
                iDigit += 6*Math.pow(10,i);
                break;
            case &quot;7&quot;:
                iDigit += 7*Math.pow(10,i);
                break;
            case &quot;8&quot;:
                iDigit += 8*Math.pow(10,i);
                break;
            case &quot;9&quot;:
                iDigit += 9*Math.pow(10,i);
                break;
            default:
        }
    }
    return iDigit;
}

WScript.echo( DECStr2Int(&quot;9876543210&quot;).toString() );
WScript.echo( DECStr2Int(&quot;0123456789&quot;).toString() );</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (-red-)]]></author>
			<pubDate>Mon, 11 Aug 2008 13:28:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=13139#p13139</guid>
		</item>
	</channel>
</rss>
