note
LanX
First there is nothing like a "hexadecimal division" in Perl. <P>
Numbers are represented internally as integers or floats in binary format.<P>
You are only free to use different base systems for the notation, see [DOC://perlnumber|<tt>perlnumber</tt>] .<P>
But the division is always the same!<P>
<I>> the division or 0x05 by 0x10 that failed as the result was 0x30 not 0x00</I><P>
really?<P>
<c> DB<17> p 0x05/0x10
0.3125
DB<18> p int(0x05/0x10)
0
</c><P>
But <C>"\x10"</C> is not a number it's a one-character string with the ASCII code 16 (= 0x10)<P>
<c> DB<25> p int(0x05/"\x10")
Illegal division by zero at (eval 33)[C:/Perl_64/lib/perl5db.pl:646] line 2.
</c><P>
<C>"\x{Hex}"</C> is just a way to use [DOC://chr|<tt>chr</tt>] inside interpolated strings!<P>
(See "escape sequences" in [HTTP://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators|perlop#Quote-and-Quote-like-Operators] for details.)<P>
<B>Stop using ASCII codes in strings for hex-numbers!</B><P>
Perl is not C, it will ONLY try to treat a string which <U>looks like a decimal number</U> as it's look-a-like number, all <U>others as number zero</U> in numerical context.<P>
<c>
DB<31> p "05"/"16" # strings with decimal(!) numbers
0.3125
</c><P>
Again Perl is not C and will NOT try to take the byte-code of a character as a number, (unless you use [DOC://ord|<tt>ord</tt>] explicitly ) !<P>
"\x10" doesn't look like a decimal number, it doesn't even look like any number at all!<P>
It's just one character which has position 16 (=0x10) in the ASCII table.<P>
<c>
DB<27> p ord("\x10")
16
DB<28> p "\x10"
► # not a number, hence 0
</c><P>
(NB: <C>►</C> shows as ► on my display this is not a number, not even a character.<P>
It's the [http://en.wikipedia.org/wiki/Data_Link_Escape|Data_Link_Escape] character in original [https://en.wikipedia.org/wiki/ASCII|ASCII], some OS try to overload it with something more meaningful.)<P>
This can only succeed (somehow) if you use the ASCII-code of a number character. <P>
Only the 10 characters "0".."9" look like a digit in ASCII.<P>
<c>
DB<1> p ord("1")
49
DB<2> p ord("\x31")
49
DB<3> p 0 + "\x31" # string = "1" looks like number
1
DB<4> p 5 / "\x31\x36" # string = "16" looks like number
0.3125
</c><P>
I hope it's clearer now, since we already had this discussion in one of your last questions!<P>
--> [id://1179502]<P>
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf<br>
<sub>(addicted to the Perl Programming Language and [http://i.dailymail.co.uk/i/pix/2014/07/14/article-2690897-1F9F6C0E00000578-463_964x629.jpg|☆☆☆☆] :)
<br> <i> [id://1153804|Wikisyntax for the Monastery]</i>
</sub> <P>
</div></div><P>
<!-- Wiki2Monks {"version":1.1416} -->
1205629
1205671