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: 10416
Joined: Fri Feb 19, 2010 10:17 am

Hex - Decimal converter

Post by richmond62 »

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: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

hand16.png
hand16.png (43.58 KiB) Viewed 10078 times
Any one for a spot of programming?
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

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: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

Just like Tarzan; now swings both ways:
DeadHexxy.png
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

Aha; now I realised I was missing something.
catcher.png
Attachments
UNHEXXER.rev.zip
2.7 to 7.0.
(23.25 KiB) Downloaded 481 times
UNHEXXER.livecode.zip
7.0 and up.
(23.24 KiB) Downloaded 478 times
TorstenHolmer
Posts: 58
Joined: Mon Oct 28, 2013 1:23 pm

Re: Hex - Decimal converter

Post by TorstenHolmer »

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: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

That's super to know. 8)
paul@researchware.com
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 154
Joined: Wed Aug 26, 2009 7:42 pm
Contact:

Re: Hex - Decimal converter

Post by paul@researchware.com »

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: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Hex - Decimal converter

Post by richmond62 »

I did it for fun.
Post Reply