Microsoft Small Basic
Program Listing:
Embed this in your website
<object id='sbapp' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='640' height='480'> <param name='source' value='http://smallbasic.com/program/ClientBin/SBWeb.xap'/> <param name='onError' value='onSilverlightError' /> <param name='background' value='white' /> <param name='minRuntimeVersion' value='3.0.40624.0' /> <param name='autoUpgrade' value='true' /> <param name='initParams' value='programId=THJ835' /> </object>
start
:
TextWindow
.
Title
=
"Binary to Decimal To Binary Converter [Amir Rke]"
TextWindow
.
Write
(
"Enter Your Choice: [1 for binary to decimal] Or [2 four decimal to binary] "
)
choice
=
TextWindow
.
ReadNumber
(
)
If
choice
=
1
Then
Goto
start1
ElseIf
choice
=
2
Then
Goto
start2
EndIf
start1
:
TextWindow
.
Write
(
"Convert Binary To Decimal..."
+
Text
.
GetCharacter
(
10
)
+
"Enter Binary Value : "
)
binary
=
TextWindow
.
ReadNumber
(
)
For
bit_Count
=
1
To
Text
.
GetLength
(
binary
)
binaryNum
=
binaryNum
+
Text
.
GetSubText
(
binary
,
Text
.
GetLength
(
binary
)
-
bit_Count
+
1
,
1
)
*
Math
.
Power
(
2
,
bit_Count
-
1
)
EndFor
TextWindow
.
ForegroundColor
=
"red"
TextWindow
.
Write
(
"Decimal form : "
+
binaryNum
+
Text
.
GetCharacter
(
10
)
)
TextWindow
.
ForegroundColor
=
"white"
binaryNum
=
""
Goto
start
start2
:
count
=
0
Bits
=
""
TextWindow
.
Write
(
Text
.
GetCharacter
(
10
)
+
"Convert Decimal To Binary..."
+
Text
.
GetCharacter
(
10
)
+
"Enter Decimal Value : "
)
N
=
TextWindow
.
ReadNumber
(
)
temp
=
N
While
N
>
0
Bits
[
count
]
=
Math
.
Remainder
(
N
,
2
)
N
=
Math
.
Floor
(
N
/
2
)
count
=
count
+
1
EndWhile
TextWindow
.
ForegroundColor
=
"Green"
TextWindow
.
Write
(
"Binary Form "
)
For
i
=
Array
.
GetItemCount
(
Bits
)
To
0
step
-
1
TextWindow
.
Write
(
Bits
[
i
]
)
EndFor
TextWindow
.
Write
(
Text
.
GetCharacter
(
10
)
)
TextWindow
.
ForegroundColor
=
"White"
Goto
start
Copyright (c) Microsoft Corporation. All rights reserved.