BinaryEncode
Michael Kann
mikekann at yahoo.com
Sun Jan 15 21:28:45 EST 2012
Rick,
You obviously know much more about binary numbers than I do, but I'll give it a try. I think that the essence of the problem is demonstrated in the following snippet:
on mouseUp
put numToChar("01110111") into x
put numToChar(119) into y
put x && y into fld 1
end mouseUp
fld 1 will then contain "_ w"
--- On Sun, 1/15/12, Rick Harrison <harrison at all-auctions.com> wrote:
From: Rick Harrison <harrison at all-auctions.com>
Subject: BinaryEncode
To: "How to use LiveCode" <use-livecode at lists.runrev.com>
Date: Sunday, January 15, 2012, 6:44 PM
I was trying some tests with binary numbers.
If I put in "w" and convert it to binary I get
"01110111" which is correct. If I then write
it out to a file, and read it back in again and
then convert it back I get "01110111" correctly,
but when converted to a character I get a "_"
which is completely wrong.
Thanks,
Rick
Code follows:
set the defaultFolder to specialFolderPath ("desktop")
put "w" into varText
answer "varText = " & varText
repeat for each char tChar in varText
put charToNum(tChar) into theNum
put baseConvert(theNum,10,2) into tBaseConverted
put char -8 to -1 of ("00000000" & tBaseConverted ) into tBaseConverted
put tBaseConverted into tConverted
end repeat
answer "tConverted = " & tConverted
put binaryencode("a*",tConverted) into VarBinaryCodedResult
put the defaultFolder & "/" & "TestFile" into TestFileName
open file TestFileName for binary write
write VarBinaryCodedResult to file TestFileName
close file TestFileName
open file TestFileName for binary read
read from file TestFileName until EOF
close file TestFileName
put it into VarTestFileData
put binaryDecode(a8,VarTestFileData,VarDecoded) into VarDisplayData
answer "VarDecoded = " & VarDecoded
answer "VarDisplayData = " & VarDisplayData
put the numToChar of VarDecoded into CharToDisplay
answer "CharToDisplay = " & CharToDisplay
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list