<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Конвертация endians]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=13965</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13965&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Конвертация endians».]]></description>
		<lastBuildDate>Mon, 23 Jul 2018 11:27:48 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127306#p127306</link>
			<description><![CDATA[<p>Китаец какой-нибудь писал, не иначе.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 23 Jul 2018 11:27:48 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127306#p127306</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127305#p127305</link>
			<description><![CDATA[<p>Нашёл в winsock2.h код, который выполняет htonll.<br /></p><div class="codebox"><pre><code>
#define _WS2_32_WINSOCK_SWAP_LONGLONG(l)            \
            ( ( ((l) &gt;&gt; 56) &amp; 0x00000000000000FFLL ) |       \
              ( ((l) &gt;&gt; 40) &amp; 0x000000000000FF00LL ) |       \
              ( ((l) &gt;&gt; 24) &amp; 0x0000000000FF0000LL ) |       \
              ( ((l) &gt;&gt;  8) &amp; 0x00000000FF000000LL ) |       \
              ( ((l) &lt;&lt;  8) &amp; 0x000000FF00000000LL ) |       \
              ( ((l) &lt;&lt; 24) &amp; 0x0000FF0000000000LL ) |       \
              ( ((l) &lt;&lt; 40) &amp; 0x00FF000000000000LL ) |       \
              ( ((l) &lt;&lt; 56) &amp; 0xFF00000000000000LL ) )


#ifndef htonll
__inline unsigned __int64 htonll ( unsigned __int64 Value ) 
{ 
    const unsigned __int64 Retval = _WS2_32_WINSOCK_SWAP_LONGLONG (Value);
    return Retval;
}
#endif /* htonll */
</code></pre></div><p>Выглядит довольно громоздко, учитывая, что у процессора есть инструкция bswap, которая делает это сразу для 32- или 64-битного регистра. А здесь получается для каждого байта сдвиг и AND, да потом ещё OR между результатами. Куча инструкций.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 23 Jul 2018 10:18:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127305#p127305</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127303#p127303</link>
			<description><![CDATA[<p>Там, во-первых, не 32 байта, а все 64, а во-вторых, нужно не только старший и младший местами поменять, а чтобы все байты были в обратном порядке, чтобы понять, запустите <a href="http://forum.script-coding.com/viewtopic.php?pid=127262#p127262">этот</a> код.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 23 Jul 2018 07:50:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127303#p127303</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127302#p127302</link>
			<description><![CDATA[<p><strong>teadrinker</strong> Ну тогда может так?<br /></p><div class="codebox"><pre><code>data := (data &lt;&lt; 32) | (data &gt;&gt; 32) ;меняем старший и младший байт местами</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Raven)]]></author>
			<pubDate>Mon, 23 Jul 2018 07:44:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127302#p127302</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127301#p127301</link>
			<description><![CDATA[<p>Ну да, я и смотрю, что в описании dll не указана, то-есть для нас её всё равно, что нет. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br /><strong>Raven</strong>, в принципе то, только надо то же самое для такого числа: 0xFFEEDDCCBBAA9988</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 23 Jul 2018 06:51:58 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127301#p127301</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127300#p127300</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>А пример использования можете показать?</p></blockquote></div><p>Судя по её определению,<br /></p><div class="codebox"><pre><code>
unsigned __int64 __inline htonll(
   unsigned __int64 value
);
</code></pre></div><p>это инлайн-функция, т.е., по сути, макрос. Когда компилятор видит в исходнике её вызов, он туда просто вставляет её код. Поэтому в ws2_32.dll её нет, там только htonl.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Mon, 23 Jul 2018 06:48:13 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127300#p127300</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127298#p127298</link>
			<description><![CDATA[<p>Это не то?<br /></p><div class="codebox"><pre><code>data := (data &lt;&lt; 8) | (data &gt;&gt; 8) ;меняем старший и младший байт местами</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Raven)]]></author>
			<pubDate>Mon, 23 Jul 2018 05:36:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127298#p127298</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127293#p127293</link>
			<description><![CDATA[<div class="quotebox"><cite>MandarinKa02 пишет:</cite><blockquote><p>.. возьму предложенную Malcev&#039;ым.</p></blockquote></div><p>Она у вас не совсем доделанная:<br /></p><div class="codebox"><pre><code>msgbox % htonl_64(0x0123456789abcdef) 
htonl_64(int) { ;x86&gt;net
	return DllCall(&quot;ntdll\RtlUlonglongByteSwap&quot;,&quot;UInt64&quot;,int,&quot;UInt64&quot;)
	;return DllCall(&quot;Ws2_32\htonll&quot;, UInt64, int, UInt64) :NOT_WORK
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 22 Jul 2018 21:48:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127293#p127293</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127291#p127291</link>
			<description><![CDATA[<p>Хах, &quot;монстр&quot; - громко сказано. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Есть монстры побольше.<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>А пример использования можете показать?</p></blockquote></div><p>Т.к. меня данная функция не работает:<br /></p><div class="codebox"><pre><code>htonl_64(int) {
	return DllCall(&quot;Ws2_32\htonll&quot;, UInt64, int, UInt64) ;NOT_WORK
}</code></pre></div><p>.. возьму предложенную <strong>Malcev</strong>&#039;ым.<br /></p><div class="codebox"><pre><code>htonl_64(int) { ;x86&gt;net
	return DllCall(&quot;ntdll\RtlUlonglongByteSwap&quot;,&quot;UInt64&quot;,int,&quot;UInt64&quot;)
	;return DllCall(&quot;Ws2_32\htonll&quot;, UInt64, int, UInt64) :NOT_WORK
}</code></pre></div><p>След. пример разбирает фрейм WebSocket&#039;а.</p><div class="codebox"><pre><code>	FIN:=(NumGet(&amp;in_data,0,&quot;UChar&quot;))&gt;&gt;7,offset:=1
	len:=NumGet(&amp;in_data,offset,&quot;UChar&quot;)-128,offset+=1 ;exclude the first bit
	OPCODE:=NumGet(&amp;in_data,0,&quot;UChar&quot;)-(FIN?128:0)

	if (len&gt;=0) {
		if(len&lt;=125)
			do_nothing()
		else if(len=126)
			len:=htons(NumGet(&amp;in_data,offset,&quot;UShort&quot;)),offset+=2 ;16bits
		else if(len=127)
			len:=htonl_64(NumGet(&amp;in_data,offset,&quot;UInt64&quot;)),offset+=8 ;64bits
	} VarSetCapacity(mask,4)
	CopyBinData(&amp;in_data+offset,&amp;mask,4),offset+=4
	XOR_crypt(&amp;in_data+offset,data,size:=len,mask)
	StrGet(&amp;data+offset,size,&quot;CP0&quot;)</code></pre></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;XOR_crypt</div><div class="fancy_spoiler"><div class="codebox"><pre><code>
XOR_crypt(data,ByRef out,size,ByRef key) {
    VarSetCapacity(out,size,0)
    loop % size {
        i:=A_Index-1
        num:=Abs(NumGet(data+0, i,&quot;UChar&quot;)-1+1)^NumGet(&amp;key+0, (i &amp; 0x3), &quot;UChar&quot;)
        NumPut(num, &amp;out,i,&quot;UChar&quot;)
    } return size
}
</code></pre></div></div></div><p>p.s. недостающие функции можно найти на форумах AHK, если загуглить.</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Sun, 22 Jul 2018 21:06:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127291#p127291</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127287#p127287</link>
			<description><![CDATA[<p><strong>MandarinKa02</strong>, ну вы просто монстр программирования, я смотрю. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br /></p><div class="quotebox"><cite>MandarinKa02 пишет:</cite><blockquote><p>Существует - <a href="https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-htonll">https://docs.microsoft.com/en-us/window … ck2-htonll</a>.</p></blockquote></div><p>А пример использования можете показать?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 22 Jul 2018 17:41:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127287#p127287</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127277#p127277</link>
			<description><![CDATA[<p>Сколько много ответов наплыло..<br />Протестировал еще вчера функцию со второго поста. (спасибо, что напомнили о ней)<br />Работает как надо.<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>ntohl(int) { ;net&gt;x86
	return DllCall(&quot;Ws2_32\ntohl&quot;, UInt, int, UInt)
}
htonl(int) { ;x86&gt;net
	return DllCall(&quot;Ws2_32\htonl&quot;, UInt, int, UInt)
}



ntohs(int) { ;net&gt;x86
	return DllCall(&quot;Ws2_32\ntohs&quot;, UShort, int, UShort)
}
htons(int) { ;x86&gt;net
	return DllCall(&quot;Ws2_32\htons&quot;, UShort, int, UShort)
}



ntohl_64(int) { ;net&gt;x86
	return htonl_64(int)
}
htonl_64(int) { ;x86&gt;net
	return DllCall(&quot;ntdll\RtlUlonglongByteSwap&quot;,&quot;UInt64&quot;,int,&quot;UInt64&quot;)
	;return DllCall(&quot;Ws2_32\htonll&quot;, UInt64, int, UInt64) :NOT_WORK
}</code></pre></div></div></div><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Скорее всего, не существует для 64 бит.</p></blockquote></div><p>Существует - <a href="https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-htonll">https://docs.microsoft.com/en-us/window … ck2-htonll</a>.<br />Только, начиная с Windows 8. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>Не знаю, зачем вам нужны эти uint64, но на всякий случай — AutoHotkey с этим типом нормально не работает, т.к. знает только int64. Поэтому может при вычислениях число испортить.</p></blockquote></div><p>Сам AHK - да, переменной такое большое значение не присвоишь, а вот NumPut&#039;ы работают без проблем.<br />Зачем нужны? Для программы сделал Web-интерфейс и была поставлена задача - связать основной скрипт с браузером. Использовал WebSocket, здесь у каждого <a href="https://tools.ietf.org/html/rfc6455#section-5.2">фрейма</a> есть структура, и если длина фрейма больше 16-битного числа(UShort), то необходимо длину фрейма поместить в int64. И здесь предстал вопрос: почему число задом наперед?</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Sun, 22 Jul 2018 14:15:29 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127277#p127277</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127274#p127274</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Скорее всего, не существует для 64 бит.</p></blockquote></div><p>Вот из-за подобных случаев я и пользуюсь AHK 32 bit.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 22 Jul 2018 13:23:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127274#p127274</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127268#p127268</link>
			<description><![CDATA[<p>Да, NumPut, похоже, знает. Но этот разнобой и путает. Тут играем, тут не играем, тут рыбу заворачивали. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> В чём, интересно, проблема с общей поддержкой uint64.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 22 Jul 2018 13:00:22 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127268#p127268</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127266#p127266</link>
			<description><![CDATA[<div class="quotebox"><cite>YMP пишет:</cite><blockquote><p>т.к. знает только int64</p></blockquote></div><p>Судя по всему, NumPut/NumGet знает UInt64, попробуй заменить в моём примере на Int64.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 22 Jul 2018 12:04:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127266#p127266</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Конвертация endians]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=127263#p127263</link>
			<description><![CDATA[<p><strong>MandarinKa02</strong><br />Не знаю, зачем вам нужны эти uint64, но на всякий случай — AutoHotkey с этим типом нормально не работает, т.к. знает только int64. Поэтому может при вычислениях число испортить.<br /></p><div class="codebox"><pre><code>
SetFormat, Integer, Hex
num = 0x8070605040302010
MsgBox, % num + 0
</code></pre></div><p>Но если нужен чисто обратный порядок байтов, то проблем быть не должно, наверно.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 22 Jul 2018 11:30:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=127263#p127263</guid>
		</item>
	</channel>
</rss>
