Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- 1st set of changes
- Added a function (binary2dec) as suggested by @MikeyWW
- Changed the binary values given as input as they were incorrect for an expected value of A (100001 to 1000001)
- Added another test sequence in the hotkey corresponding to the new function added to the script
- Removed the percent (%) signs around the pos in the SubStr function
- 2nd set of changes
- Added a function (binary2dec) as suggested by @MikeyWW and changed the name of the original binary2dec to binarytodec
- Added another test sequence in the hotkey corresponding to the new function added to the script
- 3rd set of changes
- Removed a function (bintodec)
- Added credits to the people who created the function
- Removed val 3
- Added 2 test sequences to ensure no problem is occuring
- Refined 2 functions (BintoASC and ASCtoBin)
- Removed percent (%) signs wherever they were causing problems
- 4th set of changes
- */
- !+t::
- val := ASCtoBin("HEloW")
- OutputDebug, The value of val in Binary is %val%
- val2 := BintoASC(val)
- OutputDebug, The value of val in ASCII is %val2%
- binary := " 110000 110001 110010 "
- For each, word in StrSplit(Trim(binary), " ")
- If (word > "")
- OutputDebug, % Value of bin2dec is Chr(bin2dec(word))
- OutputDebug, % Value of dec2bin is dec2bin((Asc(65)))
- OutputDebug, % bina7 := ASCIItoBin7("E")
- OutputDebug, % Bin7toASCII(bina7)
- OutputDebug, % Bin7toASCII(val2)
- Return
- BintoASC(input) ; GameNtt
- {
- For each, word in StrSplit(Trim(input), " ")
- If (word > "")
- {
- ;idk how to find the number of sequences of bits and how to take each individual sequence of bits as input so ill assume that in2 is the word extracted and input is the input
- in2 := word
- lenw := StrLen(in2)
- OutputDebug, The value of lenw is %lenw%
- while(lenw<7)
- {
- in2 := 0 . in2
- lenw++
- OutputDebug, The value of lenw is %lenw%
- }
- OutputDebug, The value of lenw is %lenw%
- power := 6
- output := 0
- pos := 1
- loop 7
- {
- val := SubStr(in2, pos, 1)
- output2 := val * (2**power)
- output := output + output2
- power--
- pos++
- OutputDebug, In Binary to ASCII, The value of val is %val%, the value of output2 is %output2%, the value of output is %output%, the value of power is %power%, the value of pos is %pos%.
- }
- outputchr := Chr(output)
- outputstr := outputstr . outputchr
- ; this would be where the loop ends
- OutputDebug, The value of outputstr is %outputstr%, the value of outputchr is %outputchr%, the value of word is %word%.
- }
- Return outputstr
- }
- ASCtoBin(input) ; GameNtt
- {
- lenstr := StrLen(input)
- outputfin := ""
- pos := 1
- OutputDebug, %lenstr%
- Loop, %lenstr%
- {
- ;power := 6
- in2 := ""
- in2 := SubStr(input, pos, 1)
- in3 := Asc(in2)
- loop 7
- {
- outputw := ""
- pow := 2**(7-(A_Index))
- if (in3>=pow)
- {
- outputfin := outputfin . 1
- in3 := in3 - pow
- }
- Else
- {
- outputfin := outputfin . 0
- }
- ;power--
- OutputDebug, In ASCII to Binary, The value of in2 is %in2%, the value of in3 is %in3%, the value of outputfin is %outputfin%, the value of pos is %pos%, the value of pow is %pow%.
- }
- pos++
- outputfin := outputfin . " "
- OutputDebug, The value of outputfin is %outputfin%
- }
- Return outputfin
- }
- bin2dec(x) ; https://www.autohotkey.com/board/topic/49990-binary-and-decimal-conversion/
- {
- Return (StrLen(x) > 1 ? bin2dec(SubStr(x, 1, -1)) << 1 : 0) | SubStr(x, 0)
- }
- dec2bin(x) ; https://www.autohotkey.com/board/topic/49990-binary-and-decimal-conversion/
- {
- Return (StrLen(x)>1 ? dec2bin(SubStr(x,1,-1))<<1:0)|SubStr(x,0)
- }
- ASCIItoBin7(asciiStr) ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=110891&p=493187#p493187
- {
- bin7 := ""
- Loop, parse, asciiStr
- {
- ascii := Asc(A_LoopField)
- if (ascii > 127)
- continue
- b := ""
- Loop 7
- b := (ascii >> (A_Index - 1)) & 1 . b
- bin7 .= b . " "
- }
- Return RTrim(bin7)
- }
- Bin7toASCII(bin7) ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=110891&p=493187#p493187
- {
- asciiStr := ""
- while RegExMatch(RegExReplace(bin7, "[^10]"), "O)[10]{7}", m, m ? m.Pos + m.Len : 1) {
- ascii := 0
- Loop 7
- ascii |= SubStr(m[0], A_Index, 1) << 7 - A_Index
- asciiStr .= Chr(ascii)
- }
- Return asciiStr
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement