In the function for Binary to ASCII, a "word" is extracted, the length of the "word" extracted is found, zeroes are added till the length equals 7, two variables, power and output are declared with the values of 6 and 0 respectively, a loop is run seven times, in which only first digit extracted with SubStr is multiplied with (2 to the power of %power%) and added to output, value of power is decreased by one and next digit is then extracted and then repeat all the above steps. This entire thing runs for the number of "words" there are. Over here "word" refers to one sequence of bits corresponding to one character (1111111 (del) is one example, 0100001(A) is another example). I don't know how to check the number of "words" in the input string or how to extract a "word" in this function.
My psuedo-code for this is
Code: Select all
BintoASC(input)
{
;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 := input
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 final value is %outputstr%, the final character is %outputchr%.
}
Now for the inverse function, ASCII to binary, a letter is extracted, it is converted to decimal (Asc()) and stored in a variable num, two variables power and output are declared with the values of 6 and no initial value (output :=) respectively, a loop is run 7 times, in which if (num>(2^%power%)), the output digit is 1, else it is 0, the output digit is then concatenated with output and the value of power is decreased by one. After the loop runs, a space is given to ensure distinction between two sequences for two characters. This entire thing runs in a loop which runs for the number for characters in the input string.
My psuedo-code for this is
Code: Select all
ASCtoBin(input)
{
lenstr := StrLen(input)
output :=
power := 6
in2 := ""
pos := 0
OutputDebug, %lenstr%
Loop, %lenstr%
{
in2 := SubStr(input, %pos%, 1)
in3 := Asc(in2)
loop 7
{
if(in3>(2^(%power%)))
output := output . 1
Else
output := output . 0
power--
pos++
OutputDebug, In ASCII to Binary, The value of in2 is %in2%, the value of in3 is %in3%, the value of output is %output%, the value of power is %power%, the value of pos is %pos%.
}
}
}
The aforementioned problems occur when I activate this hotkey which is used to troubleshoot and find what's wrong and what needs changing.
Code: Select all
!+t::
val := BintoASC(100001)
OutputDebug, %val%
val2 := ASCtoBin("A")
OutputDebug, %val2%
Return
Edit - Here's a pastebin link with the entire file contents which will be updated each subsequent post by me with the changes made written in a documentation comment at the beginning of the pastebin - https://pastebin.com/4dMwYfPf.