Doing Maths in Hex

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Doing Maths in Hex

Richmond Mathewson-2
Is it possible for Livecode to do Mathematics in Hexadecimal?

Or, am I going to have to shove Hex numbers through a Hex-to-Decimal
meat grinder,
do the Math(s) and then shove the result through a Decimal-to-Hex meat
grinder . . .

. . . all going to be a pain-in-the-b quite frankly (especially if one
is a vegetarian and doesn't
have a meat grinder).

Richmond.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Bob Sneidar-2
When I did my IP subnet calculator, there were some things that required binary, like determining what part of the IP address was the network address, and other operations required decimal. Of course, that was a unique problem as each octet is a discreet value, and not part of a *total* address. It's actually 2 addresses, the bit length of each defined by the mask. Still, when I needed to do calculations, I needed to do them in decimal.

Bob S


On May 1, 2016, at 02:04 , RM <[hidden email]<mailto:[hidden email]>> wrote:

Is it possible for Livecode to do Mathematics in Hexadecimal?

Or, am I going to have to shove Hex numbers through a Hex-to-Decimal meat grinder,
do the Math(s) and then shove the result through a Decimal-to-Hex meat grinder . . .

. . . all going to be a pain-in-the-b quite frankly (especially if one is a vegetarian and doesn't
have a meat grinder).

Richmond.

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

dunbarxx
In reply to this post by Richmond Mathewson-2
Richmond.

LC cannot add "20F" to "4CD". You need to use "baseConvert". Not onerous at all, really.

Craig
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Devin Asay

> On May 3, 2016, at 9:32 AM, dunbarx <[hidden email]> wrote:
>
> Richmond.
>
> LC cannot add "20F" to "4CD". You need to use "baseConvert". Not onerous at
> all, really.

put baseConvert(baseConvert("20F",16,10) + baseConvert("4CD",16,10),10,16)

devin


Devin Asay
Office of Digital Humanities
Brigham Young University


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Thierry Douez
and with a bit of factoring...

   put addHex( "20F", "4CD")


function addHex v1, v2
   local d1, d2
   put baseConvert( v1,16,10)  into d1
   put baseConvert( v2,16,10)  into d2
   return baseconvert( d1 + d2, 10, 16)
end addHex

Thierry



2016-05-03 18:13 GMT+02:00 Devin Asay <[hidden email]>:

>
> > On May 3, 2016, at 9:32 AM, dunbarx <[hidden email]> wrote:
> >
> > Richmond.
> >
> > LC cannot add "20F" to "4CD". You need to use "baseConvert". Not onerous
> at
> > all, really.
>
> put baseConvert(baseConvert("20F",16,10) + baseConvert("4CD",16,10),10,16)
>
> devin
>
>

--
------------------------------------------------
Thierry Douez - http://sunny-tdz.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Devin Asay

> On May 3, 2016, at 11:13 AM, Thierry Douez <[hidden email]> wrote:
>
> and with a bit of factoring...
>
>   put addHex( "20F", "4CD")
>
>
> function addHex v1, v2
>   local d1, d2
>   put baseConvert( v1,16,10)  into d1
>   put baseConvert( v2,16,10)  into d2
>   return baseconvert( d1 + d2, 10, 16)
> end addHex
>
> Thierry

Well done, Thierry!

Devin


Devin Asay
Office of Digital Humanities
Brigham Young University


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Thierry Douez
> > and with a bit of factoring...
> >
> >   put addHex( "20F", "4CD")
> >
> >
> > function addHex v1, v2
> >   local d1, d2
> >   put baseConvert( v1,16,10)  into d1
> >   put baseConvert( v2,16,10)  into d2
> >   return baseconvert( d1 + d2, 10, 16)
> > end addHex
> >
> > Thierry
>
> Well done, Thierry!
>
> Devin
>

​Thanks Devin :)

and before the next cquestion will arises:


put addHexy( "20F", "4CD", "10", "3AB")

function addHexy
   local T
   repeat with i = 1 to paramCount()
      add baseConvert(  param( i) ,16,10) to T
   end repeat
   return baseconvert( T, 10, 16)
end addHexy


​Thierry


------------------------------------------------
Thierry Douez - http://sunny-tdz.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

[-hh]
Bonjour Thierry,

Perfect.
But now, of course, the question arises, how to do that in base 42 ;-)

Hermann
Thierry Douez wrote
.. and before the next question will arise:


put addHexy( "20F", "4CD", "10", "3AB")

function addHexy
   local T
   repeat with i = 1 to paramCount()
      add baseConvert(  param( i) ,16,10) to T
   end repeat
   return baseconvert( T, 10, 16)
end addHexy

​Thierry
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Bob Sneidar-2
Don't do that. You'll break the universe.

Bob S


On May 3, 2016, at 11:53 , [-hh] <[hidden email]<mailto:[hidden email]>> wrote:

Bonjour Thierry,

Perfect.
But now, of course, the question arises, how to do that in base 42 ;-)

Hermann

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

mwieder
In reply to this post by [-hh]
On 05/03/2016 11:53 AM, [-hh] wrote:
> Bonjour Thierry,
>
> Perfect.
> But now, of course, the question arises, how to do that in base 42 ;-)

return (6 * 8)

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
--
 Mark Wieder
 ahsoftware@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

dunbarxx
There are not  even enough letters in the alphabet to reach "10" (base 42).



-----Original Message-----
From: Mark Wieder <[hidden email]>
To: How to use LiveCode <[hidden email]>
Sent: Tue, May 3, 2016 9:56 pm
Subject: Re: Doing Maths in Hex

On 05/03/2016 11:53 AM, [-hh] wrote:
> Bonjour Thierry,
>
> Perfect.
> But now, of course, the question arises, how to do that in base 42 ;-)

return (6 * 8)

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Paul Dupuis
On 5/4/2016 10:01 AM, [hidden email] wrote:
> There are not  even enough letters in the alphabet to reach "10" (base 42).

You are not considering Unicode in LC7 and 8 :-)

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Doing Maths in Hex

Peter TB Brett
In reply to this post by dunbarxx
On 04/05/2016 15:01, [hidden email] wrote:
> There are not  even enough letters in the alphabet to reach "10" (base 42).

I suppose you could use a subset of the base64 alphabet (treat uppercase
and lowercase letters as different values).

                                Peter

--
Dr Peter Brett <[hidden email]>
LiveCode Open Source Team

LiveCode 2016 Conference: https://livecode.com/edinburgh-2016/

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode