BinaryToString: Difference between revisions
Jump to navigation
Jump to search
(New page: Converts a binary variant into a string. Adapted from [http://www.autoitscript.com/autoit3/docs/functions/BinaryToString.htm AutoIt docs]. =Syntax= $str = BinaryToString(''expr'' [, ''fl...) |
m (→Example: Syntax Highlighting) |
||
Line 25: | Line 25: | ||
=Example= | =Example= | ||
Binary ANSI to String | Binary ANSI to String | ||
<syntaxhighlight lang="autoit"> | |||
$buffer = StringToBinary("Hello - ä½ å¥½") | $buffer = StringToBinary("Hello - ä½ å¥½") | ||
MsgBox(4096, "String() representation" , $buffer) | MsgBox(4096, "String() representation" , $buffer) | ||
Line 33: | Line 34: | ||
Binary UTF16-LE to String | Binary UTF16-LE to String | ||
<syntaxhighlight lang="autoit"> | |||
$buffer = StringToBinary("Hello - ä½ å¥½", 2) | $buffer = StringToBinary("Hello - ä½ å¥½", 2) | ||
MsgBox(4096, "String() representation" , $buffer) | MsgBox(4096, "String() representation" , $buffer) | ||
Line 39: | Line 41: | ||
MsgBox(4096, "BinaryToString() UTF16-LE representation" , $buffer) | MsgBox(4096, "BinaryToString() UTF16-LE representation" , $buffer) | ||
; output "Hello - ä½ å¥½" | ; output "Hello - ä½ å¥½" | ||
</syntaxhighlight> | |||
Binary UTF16-BE to String | Binary UTF16-BE to String | ||
<syntaxhighlight lang="autoit"> | |||
$buffer = StringToBinary("Hello - ä½ å¥½", 3) | $buffer = StringToBinary("Hello - ä½ å¥½", 3) | ||
MsgBox(4096, "String() representation" , $buffer) | MsgBox(4096, "String() representation" , $buffer) | ||
Line 47: | Line 51: | ||
MsgBox(4096, "BinaryToString() UTF16-BE representation" , $buffer) | MsgBox(4096, "BinaryToString() UTF16-BE representation" , $buffer) | ||
; output "Hello - ä½ å¥½" | ; output "Hello - ä½ å¥½" | ||
</syntaxhighlight> | |||
Binary UTF8 to String | Binary UTF8 to String | ||
<syntaxhighlight lang="autoit"> | |||
$buffer = StringToBinary("Hello - ä½ å¥½", 4) | $buffer = StringToBinary("Hello - ä½ å¥½", 4) | ||
MsgBox(4096, "String() representation" , $buffer) | MsgBox(4096, "String() representation" , $buffer) | ||
Line 55: | Line 61: | ||
MsgBox(4096, "BinaryToString() UTF8 representation" , $buffer) | MsgBox(4096, "BinaryToString() UTF8 representation" , $buffer) | ||
; output "Hello - ä½ å¥½" | ; output "Hello - ä½ å¥½" | ||
</syntaxhighlight> | |||
=Related Functions= | =Related Functions= | ||
[[Binary]] [[IsBinary]] [[String]] [[StringToBinary]] | [[Binary]] [[IsBinary]] [[String]] [[StringToBinary]] |
Revision as of 13:30, 10 November 2012
Converts a binary variant into a string. Adapted from AutoIt docs.
Syntax
$str = BinaryToString(expr [, flag])
Parameters
expr | Input to be converted to string. |
flag | Changes how the expression is converted.(Optional) |
Flag
Flag | Option |
1 | (Default). Binary data is considered ANSI. |
2 | Binary data is considered UTF16 Little Endian. |
3 | Binary data is considered UTF16 Big Endian. |
4 | Binary data is considered UTF8. |
Return Value
Returns a string.
Unlike String() which returns a hexidecimal representation of binary data, this function will assume the binary data is a string value and convert it appropriately.
Example
Binary ANSI to String
$buffer = StringToBinary("Hello - ä½ å¥½")
MsgBox(4096, "String() representation" , $buffer)
; output 0x48656C6C6F202D20E4BD20E5A5BD
$buffer = BinaryToString($buffer)
MsgBox(4096, "BinaryToString() ANSI representation" , $buffer)
; output "Hello - ä½ å¥½"
Binary UTF16-LE to String
<syntaxhighlight lang="autoit">
$buffer = StringToBinary("Hello - ä½ å¥½", 2)
MsgBox(4096, "String() representation" , $buffer)
; output 0x480065006C006C006F0020002D002000E400BD002000E500A500BD00
$buffer = BinaryToString($buffer, 2)
MsgBox(4096, "BinaryToString() UTF16-LE representation" , $buffer)
; output "Hello - ä½ å¥½"
Binary UTF16-BE to String
$buffer = StringToBinary("Hello - ä½ å¥½", 3)
MsgBox(4096, "String() representation" , $buffer)
; output 0x00480065006C006C006F0020002D002000E400BD002000E500A500BD
$buffer = BinaryToString($buffer, 3)
MsgBox(4096, "BinaryToString() UTF16-BE representation" , $buffer)
; output "Hello - ä½ å¥½"
Binary UTF8 to String
$buffer = StringToBinary("Hello - ä½ å¥½", 4)
MsgBox(4096, "String() representation" , $buffer)
; output 0x48656C6C6F202D20C3A4C2BD20C3A5C2A5C2BD
$buffer = BinaryToString($buffer, 4)
MsgBox(4096, "BinaryToString() UTF8 representation" , $buffer)
; output "Hello - ä½ å¥½"