<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JScript: Преобразование строки в число]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=2074&amp;type=atom" />
	<updated>2011-10-21T09:30:39Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=2074</id>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52774#p52774" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Любитель]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27037</uri>
			</author>
			<updated>2011-10-21T09:30:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52774#p52774</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52732#p52732" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[-red-]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=11960</uri>
			</author>
			<updated>2011-10-20T12:18:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52732#p52732</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52673#p52673" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Spy00000]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27060</uri>
			</author>
			<updated>2011-10-19T09:29:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52673#p52673</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52662#p52662" />
			<content type="html"><![CDATA[<p>А как можно преобразовать HEX строку в число?</p>]]></content>
			<author>
				<name><![CDATA[-red-]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=11960</uri>
			</author>
			<updated>2011-10-19T07:36:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52662#p52662</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=13157#p13157" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[fps]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=100</uri>
			</author>
			<updated>2008-08-11T17:59:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=13157#p13157</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=13144#p13144" />
			<content type="html"><![CDATA[<p>Спасибо! В справочнике не нашел этого метода :-[</p>]]></content>
			<author>
				<name><![CDATA[-red-]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=11960</uri>
			</author>
			<updated>2008-08-11T15:10:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=13144#p13144</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=13143#p13143" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2008-08-11T14:11:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=13143#p13143</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[JScript: Преобразование строки в число]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=13139#p13139" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[-red-]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=11960</uri>
			</author>
			<updated>2008-08-11T13:28:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=13139#p13139</id>
		</entry>
</feed>
