<?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=7738</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7738&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «JScript: Перевод чисел в/из разных систем счисления».]]></description>
		<lastBuildDate>Tue, 30 Oct 2012 14:16:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: JScript: Перевод чисел в/из разных систем счисления]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=65259#p65259</link>
			<description><![CDATA[<p>mshta &quot;javascript:(123456).toString(36)&quot;</p><p>cmd /c &quot;mshta &quot;javascript:(new ActiveXObject(&#039;Scripting.FileSystemObject&#039;)).GetStandardStream(1).Write((123456).toString(36));window.close();&quot; | more&quot;</p>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Tue, 30 Oct 2012 14:16:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=65259#p65259</guid>
		</item>
		<item>
			<title><![CDATA[JScript: Перевод чисел в/из разных систем счисления]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=65178#p65178</link>
			<description><![CDATA[<p>Написано по следам <a href="http://script-coding.com/forum/viewtopic.php?id=6701">скриптового аналога утилиты hex2dec</a> коллеги <strong>greg zakharov</strong>. Предложенное решение - на чистом JScript, внедренном в пакетный файл. Перевод чисел из одной системы счисления в другую. Поддерживаются основания от 2 до 36; значение по умолчанию - 10. Возможно чтение данных как из командной строки, так и из конвейера. </p><p>Примеры использования:<br /></p><div class="quotebox"><blockquote><p>C:\&gt; radix 15 /o:16<br />f</p><p>C:\&gt; radix f /i:16<br />15</p><p>C:\&gt; radix 0xf /i:16<br />15</p><p>C:\&gt; echo 0xf | radix /i:16<br />15</p></blockquote></div><p>Текст программы <strong>radix.bat</strong>:<br /></p><div class="codebox"><pre><code>
@set @x=0/*!&amp;&amp;@set @x=
@ %windir%\System32\cscript.exe //nologo //e:javascript &quot;%~dpnx0&quot; %*
@goto :eof */

//
// radix
// Converts numbers between different numerical systems
//
// Copyright (c) 2012, Ildar Shaimordanov
//

var cArgs = WScript.Arguments;
var nArgs = WScript.Arguments.Named;
var uArgs = WScript.Arguments.Unnamed;

if ( cArgs.length == 0 || nArgs.Exists(&#039;H&#039;) || nArgs.Exists(&#039;HELP&#039;) ) {
	WScript.Echo([
		WScript.ScriptName + &#039; numbers [/I:radix] [/O:radix]&#039;, 
		&#039;&#039;, 
		&#039;/I   Input radix&#039;, 
		&#039;/O   Output radix&#039;, 
		&#039;&#039;, 
		&#039;Converts numbers between different numerical systems.&#039;, 
		&#039;A radix can be one of 2 to 36. The default value is 10.&#039;
	].join(&#039;\n&#039;));
	WScript.Quit();
}

function parseRadix(value)
{
	value = nArgs.item(value) || 10;
	if ( isNaN(value) || value &lt; 2 || value &gt; 36 ) {
		throw new Error(&#039;Illegal radix: &quot;&#039; + value + &#039;&quot;.&#039;);
	}
	return value;
};

var iBase = parseRadix(&#039;I&#039;);
var oBase = parseRadix(&#039;O&#039;);

var values = uArgs;
if ( values.length == 0 ) {
	values = [];
	while ( ! WScript.StdIn.AtEndOfStream ) {
		values.push(WScript.StdIn.ReadLine());
	}
	values.item = function(i)
	{
		return this[i];
	};
}

for (var r, i = 0; i &lt; values.length; i++) {
	r = values.item(i);
	r = parseInt(r, iBase);
	r = Number(r).toString(oBase);
	WScript.StdOut.WriteLine(r);
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Sat, 27 Oct 2012 17:51:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=65178#p65178</guid>
		</item>
	</channel>
</rss>
