Convert Hex to ASCII and Vice-Versa

2 posts Page 1 of 1
Contributors
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

In this short tutorial, I'll teach you how to convert normal text (ASCII) to Hex and back. So, we will be using a library i wrote yesterday called hexJS.

To begin, add the following scripts to your previous (or new) HTML page.
Code: Select all
<script type="text/javascript" src="http://labsvisual.no-ip.biz:8888/wpitems/hexJS/js/hexjs-1.0.0.min.js"></script> 
What the first line does is that, it "imports" the hexJS library for you to use. Now you can use any of the two functions available (I know that's less, but total library is a few bytes).

Let's see the code below: we use the convert2hex(plainText) function:
Code: Select all
function processAscii(){
	var a = "Hello World!"
	var converted = convert2hex(a);
	alert(converted);
}
Let's analyse the above code, line-by-line:

The first line set a variable "a" with a string.
The next line declares the "converted" variable with the content returned by the convert2hex function.
The last line makes a pop-up with the content.

To process hex to ASCII, we will use the convert2ascii(hexString) function.

Below is the simple code to do convert a HEX string to ASCII:
Code: Select all
function processHex(){
      var a = "48656c6c6f20576f726c6421";
      var converted = convert2ascii(a);
      alert(converted);
}
It's essentially the same as the function before this, except for that fact that we have changed the contents of the variable "a" to the HEX string we want to convert.

So, that's it for this tutorial. For more information visit the official website at: http://labsvisual.no-ip.biz:8888/wpitems/hexJS/

----
Chris
Image
User avatar
noypikami
VIP - Donator
VIP - Donator
Posts: 151
Joined: Sat Dec 22, 2012 1:49 am

very interesting. nice Tutorial. :)
2 posts Page 1 of 1
Return to “Tutorials”