<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Преобразование типов данных.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12901&amp;type=atom" />
	<updated>2017-08-14T13:26:40Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=12901</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118283#p118283" />
			<content type="html"><![CDATA[<p>Всем откликнувшемся большое спасибо! Код отлично подходит под мои нужды.</p>]]></content>
			<author>
				<name><![CDATA[Raven]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30150</uri>
			</author>
			<updated>2017-08-14T13:26:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118283#p118283</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118173#p118173" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Но в зависимости от целого должно быть как то известно какова возможная точность дроби</p></blockquote></div><p>Не совсем понял, но скорее всего нет:<br /></p><div class="codebox"><pre><code>MsgBox, % FloatHexConverter(123.456) . &quot;`n&quot; . FloatHexConverter(123.456001)

FloatHexConverter(source)  {
   if source is Float
      isSourceFloat := true
   DllCall( &quot;RtlMoveMemory&quot;, isSourceFloat ? &quot;UIntP&quot; : &quot;FloatP&quot;, result
                           , isSourceFloat ? &quot;FloatP&quot; : &quot;UIntP&quot;, source
                           , Ptr, 4 )
   Return isSourceFloat ? Format(&quot;0x{:X}&quot;, result) : result
}</code></pre></div><p>Можно, конечно, добавить параметр, определяющий до какого знака округлять, но имхо это будет не очень красиво, т. к. в случае конвертации float в hex он будет лишним.</p><div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>примере уже не то число, вместо .456000 выходит .456001</p></blockquote></div><p>Это нормально, действия с float-числами всегда осуществляются с определённой погрешностью, это нужно учитывать.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-08-12T10:21:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118173#p118173</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118170#p118170" />
			<content type="html"><![CDATA[<p>Но в зависимости от целого должно быть как то известно какова возможная точность дроби, собственно и в примере уже не то число, вместо .456000 выходит .456001.<br /></p><div class="codebox"><pre><code>
 Hex := FloatHexConverter(99999.99)  ;	max 2
MsgBox, % FloatHexConverter(Hex, 6)

 Hex := FloatHexConverter(9999.999)  ;	max 3
MsgBox, % FloatHexConverter(Hex, 6)

 Hex := FloatHexConverter(999.9999)  ;	max 4
MsgBox, % FloatHexConverter(Hex, 6)

FloatHexConverter(source, Round = 0)  {
   if source is Float
      isSourceFloat := true
   DllCall( &quot;RtlMoveMemory&quot;, isSourceFloat ? &quot;UIntP&quot; : &quot;FloatP&quot;, result
                           , isSourceFloat ? &quot;FloatP&quot; : &quot;UIntP&quot;, source
                           , Ptr, 4 )
   Return isSourceFloat ? Format(&quot;0x{:X}&quot;, result) : result   ;	Round(result, Round)
}

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-08-12T00:52:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118170#p118170</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118169#p118169" />
			<content type="html"><![CDATA[<p>Не, заранее же неизвестно, до какого знака округлять.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-08-12T00:13:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118169#p118169</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118168#p118168" />
			<content type="html"><![CDATA[<p>Может ещё Round добавить.</p><div class="codebox"><pre><code>Return isSourceFloat ? Format(&quot;0x{:X}&quot;, result) : Round(result, 3)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-08-12T00:09:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118168#p118168</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118167#p118167" />
			<content type="html"><![CDATA[<p>Тогда так:<br /></p><div class="codebox"><pre><code>MsgBox, % FloatHexConverter(123.456)
MsgBox, % FloatHexConverter(0x42F6E979)

FloatHexConverter(source)  {
   if source is Float
      isSourceFloat := true
   DllCall( &quot;RtlMoveMemory&quot;, isSourceFloat ? &quot;UIntP&quot; : &quot;FloatP&quot;, result
                           , isSourceFloat ? &quot;FloatP&quot; : &quot;UIntP&quot;, source
                           , Ptr, 4 )
   Return isSourceFloat ? Format(&quot;0x{:X}&quot;, result) : result
}</code></pre></div><p><img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-08-11T23:14:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118167#p118167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118166#p118166" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
MsgBox, % HexToFloat(0x42F6E979)

HexToFloat(x) {
   DllCall(&quot;RtlMoveMemory&quot;, &quot;FloatP&quot;, f, &quot;UIntP&quot;, x, &quot;Uint&quot;, 4)
   Return f
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2017-08-11T22:41:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118166#p118166</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118165#p118165" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>MsgBox, % FloatToHex(123.456)

FloatToHex(value)
{
   Return Format( &quot;0x{:X}&quot;, DllCall(&quot;MulDiv&quot;, Float, value, Int, 1, Int, 1, UInt) )
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-08-11T22:19:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118165#p118165</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118164#p118164" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>HexToFloat(value)
{
    Return, (1 - 2 * (value &gt;&gt; 31)) * (2 ** ((value &gt;&gt; 23 &amp; 255) - 150)) * (0x800000 | value &amp; 0x7FFFFF)
}

FloatToHex(value)
{
   format := A_FormatInteger
   SetFormat, Integer, H
   result := DllCall(&quot;MulDiv&quot;, Float, value, Int, 1, Int, 1, UInt)
   SetFormat, Integer, %format%
   Return, result
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-08-11T19:59:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118164#p118164</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118163#p118163" />
			<content type="html"><![CDATA[<p>Уважаемые форумчане, всем спасибо за развернутые ответы. Был в дороге, поэтому не было меня на форме. Весь предоставляемый код который вы дали, смогу проверить только в понедельник, так как нахожусь в отъезде. Будут дельные советы или какой либо код прошу не стесняться и оставлять все это здесь, на благо общественности. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Raven]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30150</uri>
			</author>
			<updated>2017-08-11T19:44:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118163#p118163</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118161#p118161" />
			<content type="html"><![CDATA[<p>Проблема в том что голова уже не варит... пойду отдыхать.</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2017-08-11T18:03:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118161#p118161</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118160#p118160" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alectric пишет:</cite><blockquote><p><strong>Raven</strong>, будет возможность, напиши HEX данные для заранее известного real числа, а лучше для двух разных чисел.</p></blockquote></div><p>Это не вы разве писали? Я вам показал, как вы можете сами получить эти данные.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2017-08-11T18:02:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118160#p118160</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118159#p118159" />
			<content type="html"><![CDATA[<p>Так а в чём проблема превратить hex в число по тому же алгоритму, только в обратную сторону?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-08-11T18:00:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118159#p118159</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118157#p118157" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Из f31ce7d не получится</p></blockquote></div><div class="quotebox"><cite>Alectric пишет:</cite><blockquote><p>(цифры от балды, только суть)</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2017-08-11T17:55:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118157#p118157</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Преобразование типов данных.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=118156#p118156" />
			<content type="html"><![CDATA[<p>Наоборот. В <a href="http://forum.script-coding.com/viewtopic.php?pid=118128#p118128">предыдущей теме</a> мы обсуждали как получать данные из ПЛК (программируемый логический контроллер) с помощью dll. Результат работы dll - HEX строка, являющаяся копией памяти ПЛК в которой содержится значение Real представленное на картинке во втором посте. Из этой HEX строки необходимо получить Float число десятичного вида (123.456).</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2017-08-11T17:53:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=118156#p118156</id>
		</entry>
</feed>
