Teya Salat
/ /

XtScript Function: bin2hex and hex2bin

Returns binary data of a string in hexadecimal format, or decodes a hexadecimally encoded binary string.

XtScript bin2hex is a function to convert a string in binary data and return it in hexadecimal format.

On the other hand, a string written in hexadecimal format can be decoded to its binary string by using hex2bin function.

XtScript bin2hex and hex2bin function basic syntax:

<!--parser:xtscript-->
	# Encode a binary string
	call bin2hex $val=...

	# Decode a string to binary form
	call hex2bin $val=...
<!--/parser:xtscript-->

Learn XtScript bin2hex and hex2bin function from examples

Use bin2hex function in XtScript to convert a binary string to its hexadecimal value.

- Code:
<!--parser:xtscript-->
	var $string = Good morning webmasters!
	var $hex_string = call bin2hex $val=$string

	print String: $string <br/>
	print Hex string: $hex_string
<!--/parser:xtscript-->
- Result:
String: Good morning webmasters!
Hex string: 476f6f64206d6f726e696e67207765626d61737465727321

Decode the hex-encoded string using XtScript hex2bin function to its binary form.

- Code:
<!--parser:xtscript-->
	var $string = 5468697320697320612068657820656e636f646564206d657373616765
	var $decoded = call hex2bin $val=$string

	print Message: $string <br/>
	print Decoded: $decoded
<!--/parser:xtscript-->
- Result:
Message: 5468697320697320612068657820656e636f646564206d657373616765
Decoded: This is a hex encoded message