Convert Hex to ASCII and Vice-Versa
2 posts
Page 1 of 1
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.
Let's see the code below: we use the convert2hex(plainText) function:
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:
So, that's it for this tutorial. For more information visit the official website at: http://labsvisual.no-ip.biz:8888/wpitems/hexJS/
----
Chris
To begin, add the following scripts to your previous (or new) HTML page.
Code: Select all
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).<script type="text/javascript" src="http://labsvisual.no-ip.biz:8888/wpitems/hexJS/js/hexjs-1.0.0.min.js"></script>
Let's see the code below: we use the convert2hex(plainText) function:
Code: Select all
Let's analyse the above code, line-by-line:function processAscii(){
var a = "Hello World!"
var converted = convert2hex(a);
alert(converted);
}
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
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.function processHex(){
var a = "48656c6c6f20576f726c6421";
var converted = convert2ascii(a);
alert(converted);
}
So, that's it for this tutorial. For more information visit the official website at: http://labsvisual.no-ip.biz:8888/wpitems/hexJS/
----
Chris
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023