ASCII to hex converter

ASCII to hex converter



ASCII to hex converter is a useful tool for anyone working with ASCII characters and needing to convert them to hexadecimal or short "hex" numbers. The ASCII to hex converter provided below is able to convert ASCII (or even Unicode) characters to both hexadecimal and unicode numbers. The ASCII to hex converter can be used for example to encode email addresses.

ASCII to hex converter

Below you can find ASCII to hex converter which you can use to convert ASCII to hex.

Enter your ASCII text:

Hexadecimal values:

Unicode values:

Easy as that.

How the ASCII to hex converter works?

The ASCII to hex converter is simple and just converts values defined in the ASCII table. See this link for more details about the ASCII table and code ASCII.

What for can I use the ASCII to hex converter?

The ASCII to hex converter can be used for example to protect email addresses provided on a web page. Spam bots usually crawl websites and look for email addresses. If they find something in the format of xxx@yyy.zz, they consider it a valid email address, grab it, store in some database, and someone then sends you spam. There is a way to prevent spam bots from harvesting email addresses from websites. Convert your email addresses in ASCII to hexadecimal.

Email addresses are usually encoded in the following notation:

<a href="mailto:foo@example.com">foo@example.com</a>

Email harvesters look for the mailto parameter, and if they find email address following it, they harvest it. Using ASCII to hex converter, you can convert ASCII email address to something less comprehendible, such as:

<a href="%66%6F%6F%40%65%78%61%6D%70%6C%65%2E%63%6F%6D">&#x0066;&#x006F;&#x006F;&#x0040;&#x0065;&#x0078;&#x0061;
&#x006D;&#x0070;&#x006C;&#x0065;&#x002E;&#x0063;&#x006F;&#x006D;</a>

This was done using the ASCII to hex converter. The %66%6F%6F%... numbers are hexadecimal representations of ASCII characters. The &#x0066;&#x006F;&#x006F;... numbers are entities expressed in hexadecimal notation.

Is this email address protection perfect? Harvesting robots can convert hex back to ASCII, but not every harvesting robot is set up to include algorithm for doing so. Although the ASCII to hex conversion does not prevent all robots from email harvesting, ASCII to hex does help to some degree.

You can read more about other more robust email harvesting prevention techniques on the following two pages:

How to protect web pages from email harvesting
Prevent email address harvesting (part 2)

In case you have any questions about the ASCII to hex converter, you are welcome to ask in our discussion forum.

ASCII to hex converter in PHP

Let's say you want to accomplish the trick we did with the email address on the fly in your PHP script. In that case, you would use the following script to set up a PHP ASCII to hex converter.

function ascii2hex($ascii) {
$hexadecimal = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hexadecimal.=$byte." ";
}
return $hexadecimal;
}

The script above, a PHP ASCII to hex converter converts ASCII to hex. First, the ord() function returns decimal ASCII value of a character stored in $ascii, and then the result expressed in decimal gets converted to hexadecimal (see the Dec to hex converter for more details on how this is accomplished).

If you want to do the opposite, that is to convert hex to ASCII, you can use the following script:

function hex2ascii($hexadecimal){
$ascii='';
$hexadecimal=str_replace(" ", "", $hexadecimal);
for($i=0; $i<strlen($hexadecimal); $i=$i+2) {
$ascii.=chr(hexdec(substr($hexadecimal, $i, 2)));
}
return($ascii);
}

The script above converts hexadecimal to ASCII. First, the hexdec() PHP function converts the hexadecimal number stored in the $hex variable into decimal. (See the Hex to decimal converter page for more details about conversion from hex to decimal.) Then, the chr() function returns a one-character string containing the character specified by the result.

The ASCII to hex converter does not work

Ok, I have heard some people say the ASCII to hex converter fails when they convert from hex back to ASCII. That can happen, but it is not a problem with the ASCII to hex converter. It relates to the definition ASCII.

For example, someone typed the name of one Hungarian city into the ASCII box in the ASCII to hex converter. The name of the city is:

ASCII to hex

The letter ASCII to hex converter in the name of the Hungarian city gets translated into hexadecimal 151 and unicode &#337;. When you hit the Decode hex to ASCII button, there will be a problem. The hexadecimal 151 will get translated into the following two characters:

Ascii to hex convertor

Why the hexadecimal 151 in the ASCII to hex converter does not translate back to the Hungarian o? The answer can be found in the ASCII table. The ASCII table goes up to decimal 127 (0 to 127) which occupies one byte in binary. The Hungarian o is hexadecimal 151 which is decimal 337. That is more than the ASCII table can handle. The Hungarian o is a two byte character, and the basic ASCII table does not include a character to match it, so the two byte Hungarian o expressed in binary as 0000 0001 0101 0001 gets translated "incorrectly" into the two characters as shown above (negative acknowledge, dec 21, hex 15 and digit one, dec 49, hex 31). (Note: How did we find out the hex 151 is binary 0000 0001 0101 0001? See the Hex to dec converter page.)

ASCII to hex converter and other converters?

Besides the ASCII to hex converter, you can find a few other useful tools on our portal, such as

Hex to decimal converter
Dec to hex converter
RGB color picker
Word letter mixer (disorganizer)

and much more. See the categories at the menu bar at the top of the page. Read here if you want to find out more about ASCII: code ASCII or visit our discussion forum.

.

Discuss this article or this topic in our discussion forum:
(The table bellow shows a list of 8 most recent topics posted in our discussion forum. Visit our discussion forum to see more. It is possible the links below are not related to this page, but you can be certain you will find related posts in the discussion forum. You can post one yourself too.)
Email this article to a friend:
TO: 
FROM: 
2 + 6 - 3 = 
.
How can I link to this web page?

It is easy, just include the code provided below into your HTML code.

<a href="http://www.maxi-pedia.com/ascii%2Bto%2Bhex%2Bconverter" title="www.Maxi-Pedia.com: ASCII to hex converter" target="_blank">ASCII to hex converter</a>
.