Hex - Decimal converter

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Hex - Decimal converter

Post by richmond62 » Sat Apr 30, 2016 4:16 pm

You never know when you might need one of these.
UnHexxer.png
Last edited by richmond62 on Sun May 01, 2016 11:53 am, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Sat Apr 30, 2016 4:36 pm

hand16.png
hand16.png (43.58 KiB) Viewed 5591 times
Any one for a spot of programming?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Sat Apr 30, 2016 5:55 pm

I don't know who the Unicode Consortium think they are serving by being difficult and
presenting everything in Hexadecimal (and on the left is all the work I had to do to hack
their document with Decimal numbers).
GranthaGrind.gif

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Sun May 01, 2016 11:55 am

Just like Tarzan; now swings both ways:
DeadHexxy.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Sun May 01, 2016 4:50 pm

Aha; now I realised I was missing something.
catcher.png
Attachments
UNHEXXER.rev.zip
2.7 to 7.0.
(23.25 KiB) Downloaded 222 times
UNHEXXER.livecode.zip
7.0 and up.
(23.24 KiB) Downloaded 222 times

TorstenHolmer
Posts: 57
Joined: Mon Oct 28, 2013 1:23 pm
Location: Dresden, Germany

Re: Hex - Decimal converter

Post by TorstenHolmer » Tue Sep 06, 2022 11:46 am

Hi Richmond,

thanks a lot for the inspiration. I was looking for a kind of function to do that in LC and developed a shorter one, inspired by your solution:

Cheers
Torsten

Code: Select all


function Hex2Int tHex
   -- INPUT: hex value
   -- OUTPUT: integer

   put the length of tHex into tLength
   put -1 into tPower
   repeat with i = tLength down to 1
      
      add 1 to tPower
      put char i of tHex into tChar
      if tChar = "A" then put 10 into tChar
      if tChar = "B" then put 11 into tChar
      if tChar = "C" then put 12 into tChar
      if tChar = "D" then put 13 into tChar
      if tChar = "E" then put 14 into tChar
      if tChar = "F" then put 15 into tChar
      add tChar * (16^tPower) to tInt
      
   end repeat
   
   return tInt

end Hex2Int

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Tue Sep 06, 2022 11:53 am

That's super to know. 8)

paul@researchware.com
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 135
Joined: Wed Aug 26, 2009 7:42 pm
Location: Randolph, MA USA
Contact:

Re: Hex - Decimal converter

Post by paul@researchware.com » Wed Sep 07, 2022 12:47 pm

This may have already come up, but why write a base conversion routine when one is alreayd built into Livecode?

See baseConvert(number, originalBase, destinationBase) in the Dictionary

For base hex to decimal converstion:

put baseConvert(myHexNumberVariable,16,10) into myDecNumberVariable
Paul Dupuis
Researchware, Inc.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9356
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Hex - Decimal converter

Post by richmond62 » Wed Sep 07, 2022 2:38 pm

I did it for fun.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”