Create a text field and two buttons, one for coverting to binary and another for converting to original form.
--Logic for converting to Binary.
--*******************************
global charlist
-- list in which each character entered is stored as a seperate element.
global cnt
-- cnt to keep track of total caharacters entered into a text field.
global binlist
-- list which stores the binary value of each character.
global templist
-- list used for temporary storage.
global bin
-- flag set as soon as the entered text is converted to binary.
global dec
-- flag set as soon as the binary form is converted back to original.
property tempvar
-- variable used to store each character from the list during each repetion
of the loop.
property remd
-- remainder value during division.
property totchars
-- total number of values in the binlist.
on mouseUp
-- Mouseup on a button
if bin = 0 then
if the text of field "entext" = empty then
alert "Please enter text"
exit
else
binlist = []
templist = []
charlist = []
cnt = the number of chars of field "entext"
repeat with i = 1 to cnt
append charlist, chartonum(char i of field "entext")
updatestage
end repeat
repeat with x = 1 to cnt
tempvar = charlist[x]
put tempvar
repeat while tempvar > 1
remd = tempvar mod 2
append templist, remd
put remd before field "remder"
updatestage
tempvar = tempvar / 2
end repeat
-- The field "remder" is used to temporarily store the binary values
during processing.
put tempvar before field "remder"
templist = []
templist[x] = the text of field "remder"
append binlist, templist[x]
put binlist
set the text of field "remder" to empty
end repeat
set the text of field "entext" to empty
totchars = count(binlist)
repeat with s = 1 to totchars
put binlist[s] after field "entext"
updatestage
end repeat
bin = 1
dec = 0
end if
else
nothing
end if
end
--Conversion from Binary to Original text
--***************************************
global binlist
global sumtot
-- variable used to calculate the sum total of power values.
global expo
-- variable used to store successive exponential values.
global bin
global dec
property tch
-- total number of characters in the binlist.
property tchars
-- total number of characters stored in the temporary field "bintext"
property t
on mouseUp
if dec = 0 then
tch = count(binlist)
set the text of field "entext" to empty
repeat with x = 1 to tch
put binlist[x] into field "bintext"
tchars = the number of chars of field "bintext"
repeat with y = tchars down to 1
t = value(char y of field "bintext") * (power(2,expo))
sumtot = sumtot + t
expo = expo + 1
updatestage
end repeat
put numtochar(integer(sumtot)) after field "entext"
sumtot = 0
expo = 0
end repeat
dec = 1
bin = 0
else
nothing
end if
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA