In computers all information is ultimately stored and processed as numbers. This means that text characters must also be stored as numbers. The most commonly used system for representing the Latin alphabet on computers is called ASCII—the American Standard Code for Information Interchange—although there are several variations of this standard. The first part of this exercise is designed to help you become familiar with this standard and to introduce you to tools that LiveCode provides for accessing the underlying codes for text characters.
on mouseUp
put empty into fld "ascii"
repeat with i = 0 to 127
put numToChar(i) into line i+1 of fld "ascii"
end repeat
end mouseUp
put i & tab & numToChar(i) into line i+1 of fld "ascii"
Code number:
Character:
While it is easy for us humans to think in base 10 (after all, we have 10
fingers!), computers like base 2--ones and zeros. For programmers it is more
efficient to express numbers in base 16--the digits 0 through F--also called
hexdecimal. Let's add columns that show the codes in these bases. The way to
change the base of a number in LiveCode is with the baseConvert()
function:
syntax: baseConvert(number to convert,from base,to
base)
So to convert the number 27 from base 10 to base 16 you would do this:
put baseConvert(27,10,16) into myVar
Change the statement inside the repeat loop to add a column for the hexidecimal codes for each letter:
put i & tab & numToChar(i) & tab & baseConvert(i,10,16) into line i+1 of fld "ascii"
How would you change the statement to add the base 2 code for each character?
Try it in your button.
What is strange about the columns on line 9? Why might this have happened?
(To help answer this question enter put charToNum(tab)
in the
message box.)
What is strange about line 10? Why does nothing appear after the line number?
(Hint: charToNum (LF)
)