On Apr 17, 2017, at 5:19 PM,Cannon Smith wrote:

> Here is an example string coming across the wire: “02ABC877FAFB0200”. This 
> represents 8 bytes in little endian ordering. The algorithm that was given me 
> was to break the string into bytes (“02”, “AB”, “C8”, etc.) and then loop 
> through each byte, converting it to decimal and applying a little math. For 
> example:
> 
> Hex “02” = Decimal 2.         SubValue = 2     * (256^0)  = 2
> Hex “AB" = Decimal 171.    Subvalue = 171 * (256^1) =  43776
> Hex “C8" = Decimal 200.    Subvalue = 200 * (256^2) =  13107200
> Hex “77" = Decimal 119.     Subvalue = 119 * (256^3) =1996488704
> Hex “FA" = Decimal 250.    Subvalue = 250 * (256^4) =  1073741824000
> Hex “FB" = Decimal 251.    Subvalue = 251 * (256^5) =  275977418571776 (4D 
> gives 2.759774185718e+14)
> Hex “02" = Decimal 2.        Subvalue = 2      * (256^6) = 562949953421312 
> (4D gives 5.629499534213e+14)
> Hex “00" = Decimal 0.        Subvalue = 0      * (256^7) = 0
> 
> Once this is done, all the subvalue results are summed which should give the 
> RFID number. In this case it should be 840003123456770. But 4D gives this: 
> 8.400031234568e+14. As you can see, the last three digits are not correct.
> 
> So, does anyone know a way to convert the string “02ABC877FAFB0200” to the 
> string “840003123456770” within 4D’s limitations?

So what you need is a way to do math of very big integers. You only need to do 
basic math functions of add and multiple. Convert could the exponential to a 
series of multiplies. 

There is a code library on 4D Forums called Math4D that might do the trick for 
you. I think the method you are looking for is MATH_GrandsEntiers.

http://forums.4d.fr/Post/EN/4010516/1/4021906#4021906

If if that doesn’t work out, I’d look at using a Javascript implementation. 
Like:  https://www.npmjs.com/package/big-integer

I did notice this on the above web page:

Note that Javascript numbers larger than 9,007,199,254,740,992 and smaller than 
-9007199254740992 are not precisely represented numbers and will not produce 
exact results. If you are dealing with numbers outside that range, it is better 
to pass in strings.

Maybe you could use native Javascript. It has 15 digit integer precision. Maybe 
an offscreen web area and WA EXECUTE JAVASCRIPT FUNCTION with a custom function 
could be written to return the result.

That’s all the ideas I could come up with in 10 minutes.

Tim

********************************************
Tim Nevels
Innovative Solutions
785-749-3444
timnev...@mac.com
********************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to