Page 1 of 1

Hex - Decimal converter

Posted: Sat Apr 30, 2016 4:16 pm
by richmond62
You never know when you might need one of these.
UnHexxer.png

Re: Hex - Decimal converter

Posted: Sat Apr 30, 2016 4:36 pm
by richmond62
hand16.png
hand16.png (43.58 KiB) Viewed 7849 times
Any one for a spot of programming?

Re: Hex - Decimal converter

Posted: Sat Apr 30, 2016 5:55 pm
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

Re: Hex - Decimal converter

Posted: Sun May 01, 2016 11:55 am
by richmond62
Just like Tarzan; now swings both ways:
DeadHexxy.png

Re: Hex - Decimal converter

Posted: Sun May 01, 2016 4:50 pm
by richmond62
Aha; now I realised I was missing something.
catcher.png

Re: Hex - Decimal converter

Posted: Tue Sep 06, 2022 11:46 am
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

Re: Hex - Decimal converter

Posted: Tue Sep 06, 2022 11:53 am
by richmond62
That's super to know. 8)

Re: Hex - Decimal converter

Posted: Wed Sep 07, 2022 12:47 pm
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

Re: Hex - Decimal converter

Posted: Wed Sep 07, 2022 2:38 pm
by richmond62
I did it for fun.