Is it possible to store the binary or hex code of any file into a variable?
Binary (0 and 1)
Hex (0 to 9 and A to F)
How to get the binary or hex code of any file?
Re: How to get the binary or hex code of any file?
Google is your friend too (well, sort of) ...
https://autohotkey.com/board/topic/6946 ... d-writing/
https://autohotkey.com/boards/viewtopic.php?t=6895
https://autohotkey.com/board/topic/6946 ... d-writing/
https://autohotkey.com/boards/viewtopic.php?t=6895
Re: How to get the binary or hex code of any file?
Here is an example of reading/writing binary using the AutoHotkey exe.
See my JEE_BinDataToHex/JEE_HexToBinData functions here:
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596
For hex to bin numbers / bin to hex numbers:
Code: Select all
q:: ;read/write binary files
;note: to copy any file you can just use FileCopy
;based on code from here:
;conversion logic, v1 = -> v1 := -> v2, two-way compatibility - Page 5 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=37&t=27069&p=169780#p169780
vPath := A_AhkPath
oFile := FileOpen(vPath, "r")
oFile.Pos := 0
vSize := oFile.Length
oFile.RawRead(vData, oFile.Length)
oFile.Close()
vPath = %A_Desktop%\z ahk exe copy %A_Now%.exe
if FileExist(vPath)
return
oFile := FileOpen(vPath, "w")
oFile.RawWrite(vData, vSize)
oFile.Close()
return
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596
For hex to bin numbers / bin to hex numbers:
Code: Select all
q:: ;hex to bin numbers
vHex := "0123456789ABCDEF"
vList := "0000,0001,0010,0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111"
vBin := vHex
Loop, Parse, vList, % ","
vBin := StrReplace(vBin, Format("{:X}", A_Index-1), A_LoopField)
MsgBox, % vBin
MsgBox, % LTrim(vBin, "0")
return
w:: ;bin to hex numbers
vBin := "0000000100100011010001010110011110001001101010111100110111101111"
oArray := {"0000":0,"0001":1,"0010":2,"0011":3,"0100":4,"0101":5,"0110":6,"0111":7,"1000":8,"1001":9,"1010":"A","1011":"B","1100":"C","1101":"D","1110":"E","1111":"F"}
;prepend zeros to ensure the length is a multiple of 4
vPfx := SubStr("000", Mod(StrLen(vBin)+3, 4)+1)
vBin := RTrim(RegExReplace(vPfx vBin, "....", "$0,"), ",")
vHex := ""
VarSetCapacity(vHex, StrLen(vBin)/2)
Loop, Parse, vBin, % ","
vHex .= oArray["" A_LoopField]
MsgBox, % vHex
MsgBox, % LTrim(vHex, "0")
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: How to get the binary or hex code of any file?
so, is it not possible to read any type of file and save its binary (0 and 1) or Hex (0 to 9 and A to F) code directly into a variable?
by using RawRead(), long Chinese characters string are stored into the variable (整瑳汬汬汬 ...)
then, by using RawWrite(), the original unicode or ansi characters are stored into the file instead the file's binary or hex code!
by using RawRead(), long Chinese characters string are stored into the variable (整瑳汬汬汬 ...)
then, by using RawWrite(), the original unicode or ansi characters are stored into the file instead the file's binary or hex code!
Re: How to get the binary or hex code of any file?
Can someone here tell me why the script returns Chinese characters instead the bin or the hex code of "test.txt" file?
Note that, the "test.txt" file only contains Ansi characters, does not contain any Chinese characters!
Note that, the "test.txt" file only contains Ansi characters, does not contain any Chinese characters!
Re: How to get the binary or hex code of any file?
- In that 'gui, add, edit' line, if run in Unicode versions of AHK, it will regard that data as a UTF-16 LE string, and display text accordingly.
- To read text from a text file, use FileRead.
- To read text from data, use StrGet.
- To display binary data as a hex string, you could use my function above.
- To display binary data as 0s and 1s, convert it to a hex string, and then to 0s and 1s, by using StrReplace/RegExReplace.
- To read text from a text file, use FileRead.
- To read text from data, use StrGet.
- To display binary data as a hex string, you could use my function above.
- To display binary data as 0s and 1s, convert it to a hex string, and then to 0s and 1s, by using StrReplace/RegExReplace.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA