baseConvert() & 32-bit ops (was Best array population & access optimization)
Dar Scott
dsc at swcp.com
Sat Jun 21 14:56:01 EDT 2003
On Saturday, June 21, 2003, at 01:12 PM, Mark Brownell wrote:
> On Saturday, June 21, 2003, at 09:58 AM, Dar Scott wrote:
>> Wanna see my test script and results?
>
> Yes please. I want to run the different OS versions of the hexed
> boxes through it. It will be nice to see what happens with the
> constants that seem to work if the unsigned numbers are the same.
on mouseUp
put empty into field "Report"
--
put ( (2^32)-1 )&"" into allOnes
put (allOnes bitAnd allOnes) & LF & LF after field "Report"
--
put allOnes & LF after field "Report"
put baseConvert(allOnes,10, 2) & " " after field "Report"
put baseConvert(allOnes,10,10) & " " after field "Report"
put baseConvert(allOnes,10,16) & " " after field "Report"
put baseConvert(allOnes,10,30) & LF after field "Report"
put baseConvert(allOnes,10,10) into ones10
put (ones10 bitAnd ones10) & LF after field "Report"
put LF after field "Report"
--
put "FFFFFFFF" into allOnes
put allOnes & LF after field "Report"
put baseConvert(allOnes,16, 2) & " " after field "Report"
put baseConvert(allOnes,16,10) & " " after field "Report"
put baseConvert(allOnes,16,16) & " " after field "Report"
put baseConvert(allOnes,16,30) & LF after field "Report"
put baseConvert(allOnes,16,10) into ones10
put baseConvert(ones10 ,10,16) & " " after field "Report"
put baseConvert(-ones10,10,16) & " " after field "Report"
put (ones10 bitAnd ones10) & LF after field "Report"
put LF after field "Report"
--
put "80000000" into oneOnes
put oneOnes & LF after field "Report"
put baseConvert(oneOnes,16, 2) & " " after field "Report"
put baseConvert(oneOnes,16,10) & " " after field "Report"
put baseConvert(oneOnes,16,16) & " " after field "Report"
put baseConvert(oneOnes,16,30) & LF after field "Report"
put baseConvert(oneOnes,16,10) into one10
put baseConvert(one10 ,10,16) & " " after field "Report"
put baseConvert(-one10 ,10,16) & " " after field "Report"
put (one10 bitAnd one10) & LF after field "Report"
put LF after field "Report"
end mouseUp
And the not very pretty result is this:
4294967295
4294967295
11111111111111111111111111111111 -4294967295 FFFFFFFF 5QMCPQF
0
FFFFFFFF
11111111111111111111111111111111 -4294967295 FFFFFFFF 5QMCPQF
-FFFFFFFF FFFFFFFF 0
80000000
10000000000000000000000000000000 -2147483648 80000000 2SB6CS8
-80000000 80000000 0
If I make a test with better output, I'll send you that.
The main things to notice is that all ones comes out as -4294967295 in
decimal and not 4294967295 or even -1. Also, note that bitAnd of that
doesn't get all ones either.
>
> also, not being familiar with binaryEncode how would you write the
> following using binaryEncode?
>
> put charToNum("F") + (charToNum("o") * 256 ) + ( charToNum("r") *
> 65536 ) + ( charToNum("m") * 16777216 ) into xL
local halfBlock -- required
put binaryDecode("N","Form",halfBlock) into numConverted
In converting strings to blocks use 'char i to (i+3) of plainText'
instead of "Form" and pay attention to the end. The variable
numConverted with be 0 for short data.
You use binaryEncode for the other direction and, perhaps, in the first
part of the Blowfish F function. (The later might take two steps.)
Dar Scott
More information about the use-livecode
mailing list