Jump to content
Sign in to follow this  

Binary( )conversion fail on file opened in 'text' mode

Recommended Posts


I found that using  Binary(FileRead($x)) with FileOpen($x) can cause failed reads (blank) on systems that use 2byte per letter text encoding.

It's not clearly stated in the help file that the default mode for FileOpen() is text and should not be used to read binary data. Or, this may be a bug in Autoit.

I in this example, $data should return "FF000000" through "C00000", but as you can see from my screen shot, it returns empty reads between FD and DF. This seems to happen on computers set to 2byte per letter text encodings.


Local $data

For $i = 1 to 0xff
$data= Binary($i) & Binary($data)

$file = FileOpen(@WorkingDir & "\.example_DELETE.txt",2)
FileWrite($file, $data)

$data = ""
For $i = 1 To 0xff
$data = Binary($data) & Binary(FileRead($file,1))




Edited by EddieBoy

Share this post

Link to post
Share on other sites

I'll just add, if you live in the US and have had programs fail when sent overseas to unicode etc users, this issue may be the culprit.

 When I changed my code to use "forced binary" FileOpen($x,16), the problem went away.  

Share this post

Link to post
Share on other sites

Unicode is alqaeda etc.

  • Like 4




Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.