<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><font face="Arial">No dobře, že vypisuje jeden znak pro hex 0-F
má logiku, ale jak může být char znaménkový, když je to znak?
Nedochází mi rozdíl, mezi char a unsigned char?</font><br>
</p>
<pre class="moz-signature" cols="72">Martin Záruba</pre>
<div class="moz-cite-prefix">Dne 26.8.2023 v 12:23 Jindroush
napsal(a):<br>
</div>
<blockquote type="cite"
cite="mid:82cd01e8-25b3-38af-6b46-b50a993f8ffb@seznam.cz">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div class="moz-cite-prefix">To chovani je ale prece v poradku,
proc jste ocekaval neco jineho? Proste to vypisuje cislo v dane
bazi, tj. 0 je v hexu 0. Char je znamenkovy a zjevne znamenkove
rozsiril -1 byte na -1 int a to je pak 0xFFFFFFFF.<br>
Na printovani dvouznakoveho hexu bych si napsal vlastni funkci,
ale ne zbytecne tu s ohejbakem.<br>
<br>
<pre class="lang-c s-code-block"><code class="hljs language-c"> <span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> hi = (input >> <span class="hljs-number">4</span>) & <span class="hljs-number">0xf</span>;
<span class="hljs-type">unsigned</span> <span class="hljs-type">char</span> lo = input & <span class="hljs-number">0xf</span>;
hi += hi < <span class="hljs-number">10</span> ? <span class="hljs-string">'0'</span> : <span class="hljs-string">'A'</span> - <span class="hljs-number">10</span>;
lo += lo < <span class="hljs-number">10</span> ? <span class="hljs-string">'0'</span> : <span class="hljs-string">'A'</span> - <span class="hljs-number">10</span>;
a tady vytisknout hi/lo na seriak
</code></pre>
</div>
<div class="moz-cite-prefix">On 26.08.2023 11:47, Martin Záruba
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:2c889083-6832-17d3-dbb2-d538daea7c6a@volny.cz">
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<p>Potřeboval jsem proměnné vypsat v hexadecimálním tvaru. K
mému údivu</p>
<div style="color: #4e5b61;background-color: #ffffff;font-family: Consolas, 'Courier New', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">println</span><span style="color: #434f54;">(</span><span style="color: #005c5f;">0</span><span style="color: #4e5b61;">,HEX</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">println</span><span style="color: #434f54;">(</span><span style="color: #005c5f;">254</span><span style="color: #4e5b61;">,HEX</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">println</span><span style="color: #434f54;">(</span><span style="color: #005c5f;">255</span><span style="color: #4e5b61;">,HEX</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #00979d;">char</span><span style="color: #4e5b61;"> d=0x</span><span style="color: #005c5f;">FF</span><span style="color: #4e5b61;">;</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">println</span><span style="color: #434f54;">(</span><span style="color: #4e5b61;">d,HEX</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div>
dá hodnoty:</div>
<div style="color: #4e5b61;background-color: #ffffff;font-family: Consolas, 'Courier New', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;">
</div>
<pre class="moz-signature" cols="72">0
FE
FF
FFFFFFFF
dělá Vám to taky nebo už blbnu? Očekával jsem dva hexadecimální znaky ve všech případech. Obelstil jsem to touto funkcí:
</pre>
<div style="color: #4e5b61;background-color: #ffffff;font-family: Consolas, 'Courier New', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #00979d;">void</span><span style="color: #4e5b61;"> </span><span style="color: #d35400;">hexprint</span><span style="color: #434f54;">(</span><span style="color: #00979d;">char</span><span style="color: #4e5b61;"> </span><span style="color: #434f54;">c)</span><span style="color: #4e5b61;"> </span><span style="color: #434f54;">{</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #728e00;">if</span><span style="color: #4e5b61;"> </span><span style="color: #434f54;">(</span><span style="color: #d35400;">byte</span><span style="color: #434f54;">(</span><span style="color: #4e5b61;">c</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;"><</span><span style="color: #005c5f;">16</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">print</span><span style="color: #4e5b61;"> </span><span style="color: #434f54;">(</span><span style="color: #005c5f;">"0"</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div><div><span style="color: #4e5b61;"> </span><span style="color: #d35400;">Serial</span><span style="color: #4e5b61;">.</span><span style="color: #d35400;">print</span><span style="color: #434f54;">(</span><span style="color: #d35400;">byte</span><span style="color: #434f54;">(</span><span style="color: #4e5b61;">c</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">,HEX</span><span style="color: #434f54;">)</span><span style="color: #4e5b61;">;</span></div><span style="color: #434f54;">}</span><span style="color: #4e5b61;">;</span></div>
<pre class="moz-signature" cols="72">Ale je to rovnák na ohýbák.
--
Martin Záruba
</pre>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
HW-list mailing list - sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz" moz-do-not-send="true">www.HW.cz</a>
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:Hw-list@list.hw.cz" moz-do-not-send="true">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list" moz-do-not-send="true">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
Jindroush <a class="moz-txt-link-rfc2396E" href="mailto:jindroush@seznam.cz" moz-do-not-send="true"><jindroush@seznam.cz></a></pre>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
HW-list mailing list - sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz">www.HW.cz</a>
<a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
</blockquote>
</body>
</html>