What is the size limit for numbers in LC? -- and multiplying really large numbers

David Bovill david.bovill at gmail.com
Sat Sep 7 15:07:02 EDT 2013


You are inspiring me Geoff! Was about to give up on trying to create the
"64 bit checksum" of a movie file in LiveCode and insted take the ruby code
and call it fro the command line - but using your handler I guess I can do
the 64bit Integer calculations. If you guys could give me a few more
pointers that would be great:

To recap:

> Hash code is based on Media Player Classic<http://sourceforge.net/projects/guliverkli/>.
> In natural language it calculates: size + 64bit chksum of the first and
> last 64k (even if they overlap because the file is smaller than 128k).
>

The key section of the ruby code from one of the examples found here (
http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#Ruby)
is:

# Q = unsigned long long = 64 bit
f.read(CHUNK_SIZE).unpack("Q*").each do |n|
 hash = hash + n & 0xffffffffffffffff # to remain as 64 bit number
end

Mark's pseudocode is:
initialize the checksum to 0
ignore any overflows (just use the lowest 64 bits)
read the first 64k bytes of the file
repeat 8192 times:
  grab an 8-byte chunk as a 64-bit integer
  add it to the checksum
read the last 64k bytes of the file
repeat 8192 times:
  grab an 8-byte chunk as a 64-bit integer
  add it to the checksum

The bits I don't quite get yet are:

   1. ignore any overflows (just use the lowest 64 bits)
   2. grab an 8-byte chunk as a 64-bit integer
   3. add it to the checksum

My understanding is that I should be:

   1. Using binaryDecode to "grab an 8-byte chunk as a 64-bit integer"
   2. Livecode's format function to "ignore any overflows (just use the
   lowest 64 bits)"

However, as I understand it LiveCode does not do 64bit integers, which is
why the "Q" or "q" options for binaryDecode are not available? So I am not
quite sure what I should be grabbing.

My guess is that maybe I should be just looping through the 64k bytes (now
would that be the same as 64000 chars or 8*8192 chars?) and grabbing the
first 8 chars and then converting this to a binary number of ) & 1's ?

Maybe I should use this:  get binarydecode ("d", someBytes, someInteger) ?

On each addition (within the repeat loop) trim the result of the addition
using LiveCode's format function (in ruby I think this is done with
0xffffffffffffffff)-
this is to "use the lowest 64 bits". Or is this just the end 8 chars?



More information about the use-livecode mailing list