Microsoft Small Basic

Program Listing: THJ835-2
Cr = Text.GetCharacter(10)
Txt = "0=Binary;1=Decimal"
TextWindow.Title = "Binary to Decimal To Binary Converter [Amir Rke]"
While 1 = 1
TextWindow.ForegroundColor = "White"
TextWindow.Write(Cr + "Enter Your Choice : [1 for Binary to Decimal] Or [2 for Decimal to Binary] ")
Choice = TextWindow.ReadNumber() - 1
TextWindow.Write("Convert " + Txt[Choice] + " To " + Txt[Math.Abs(Choice - 1)] + " ..." + Cr + "Enter " + Txt[Choice] + " Value : ")
If Choice = 0 Then
BinLine = TextWindow.ReadNumber()
DecValue = 1
For NbFois = Text.GetIndexOf(BinLine, "1") + 1 To Text.GetLength(BinLine)
DecValue = DecValue * 2 + Text.GetSubText(BinLine,NbFois,1)
EndFor
TextWindow.ForegroundColor = "red"
TextWindow.WriteLine("Decimal form : " + DecValue)
ElseIf Choice = 1 Then
DecValue = TextWindow.ReadNumber()
BinLine = "!"
While DecValue > 0
BinLine = Math.Remainder(DecValue,2) + BinLine
DecValue = Math.Floor(DecValue / 2)
EndWhile
TextWindow.ForegroundColor = "Green"
TextWindow.Writeline("Binary Form : " + text.GetSubText(BinLine, 1, Text.GetLength(BinLine) - 1))
EndIf
EndWhile