Ha! I saw an episode of "Big Bang Theory" where they were arguing over the binary translation of English (how many zeros and ones there should be).
Amir had made a Decimal to Binary converter that I featured, and I mentioned that a text to binary converter would be pretty sweet.
Well now (through the magic of Small Basic) Amir CPS has made it possible to have a conversation with zeros and ones that you have encoded in binary:
Get your geek on! Go translate this into English! You can double click this one line, and then copy all the text at once:
010000110110111101101101011011010110010101101110011101000010000001101111011011100010000001110100011010000110010100100000011000100110110001101111011001110010000001111001011011110111010101110010001000000110011001100001011101100110111101110010011010010111010001100101001000000110001101101111011011000110111101110010
Or you can paste in the four lines, one at a time, no spaces:
01000011011011110110110101101101011001010110111001110100001000000110111101101110001
0000001110100011010000110010100100000011000100110110001101111011001110010000001111
0010110111101110101011100100010000001100110011000010111011001101111011100100110100
10111010001100101001000000110001101101111011011000110111101110010
It's a text to binary and binary to text converter!
Import : FTK803
Small change in codes to handle "NewLine" character
Import : BTN178
And here's the code...
1.GraphicsWindow.Width = 4002.GraphicsWindow.Height = 3003.GraphicsWindow.Title = "Text to Binary :
Binary to Text"4.5.TextBox =
Controls.AddMultiLineTextBox(10,10)6.Controls.SetSize(TextBox,380,250)7.ButtonTB =
Controls.AddButton("Convert to
Binary",10,265)8.ButtonBT =
Controls.AddButton("Convert to
Text",140,265)9.Controls.ButtonClicked =
onClick10.11.Sub onClick12. LastButton =
Controls.LastClickedButton13. If LastButton =
"Button1" Then14. ConvertToBinary()15. Else16. ConvertToText()17. EndIf18.EndSub19.Sub ConvertToBinary20. String = Controls.GetTextBoxText(TextBox)21. For i = 1 To Text.GetLength(String)22. CharCode =
Text.GetCharacterCode(Text.GetSubText(String,i,1))23. 'convert ascii codes into
binary24. bit = ""25. binval = ""26. Count = 027. While CharCode >
028. bit[Count] = Math.Remainder(CharCode,2)29. CharCode =
Math.Floor(CharCode
/ 2)30. Count = Count + 131. EndWhile32. For j = Array.GetItemCount(bit) To 0 Step -133. binval = Text.Append(binval,bit[j])34. EndFor35. 'add leading zero to make binary
value even36. For b = 0 To 8 - Text.GetLength(binval)37. binval = Text.Append(0,binval)38. EndFor39. longbin =
Text.Append(longbin,binval)40. EndFor41. Controls.SetTextBoxText(TextBox,longbin)42. longbin =
""43.EndSub44.Sub ConvertToText45. Binary = Controls.GetTextBoxText(TextBox)46. If Math.Remainder(Text.GetLength(Binary),8) <> 0 Then47. GraphicsWindow.ShowMessage("Binary is un
even","Error")48. Else49. For g = 1 To Text.GetLength(Binary) Step 850. Binarychar =
Text.GetSubText(Binary,g,8)51. 'Convert binary to
decimal52. For bit_Count =
1 To Text.GetLength(Binarychar)53. binaryNum =
binaryNum + Text.GetSubText(Binarychar,Text.GetLength(Binarychar)-bit_Count+1,1)*Math.Power(2,bit_Count-1)54. EndFor55. 'get char from ascci
code56. Char = Text.GetCharacter(binaryNum)57. binaryNum =
""58. 'append char59. LongString =
Text.Append(LongString,Char)60. EndFor61. Controls.SetTextBoxText(TextBox,LongString)62. LongString =
""63. EndIf64.EndSub
What do you think?
Do you need a Klingon to Binary converter? =^)
Enjoy!
- Ninja Ed