Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^3: hexadecimal division (string to number casting only for decimal! numbers! )by LanX (Saint) |
on Dec 16, 2017 at 14:30 UTC ( [id://1205679]=note: print w/replies, xml ) | Need Help?? |
First there is nothing like a "hexadecimal division" in Perl. Numbers are represented internally as integers or floats in binary format. You are only free to use different base systems for the notation, see perlnumber . But the division is always the same! > the division or 0x05 by 0x10 that failed as the result was 0x30 not 0x00 really?
But "\x10" is not a number it's a one-character string with the ASCII code 16 (= 0x10)
"\x{Hex}" is just a way to use chr inside interpolated strings! (See "escape sequences" in perlop#Quote-and-Quote-like-Operators for details.) Stop using ASCII codes in strings for hex-numbers! Perl is not C, it will ONLY try to treat a string which looks like a decimal number as it's look-a-like number, all others as number zero in numerical context.
Again Perl is not C and will NOT try to take the byte-code of a character as a number, (unless you use ord explicitly ) ! "\x10" doesn't look like a decimal number, it doesn't even look like any number at all! It's just one character which has position 16 (=0x10) in the ASCII table.
(NB: ► shows as ► on my display this is not a number, not even a character. It's the Data_Link_Escape character in original ASCII, some OS try to overload it with something more meaningful.) This can only succeed (somehow) if you use the ASCII-code of a number character. Only the 10 characters "0".."9" look like a digit in ASCII.
I hope it's clearer now, since we already had this discussion in one of your last questions!
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|