Hex - Decimal converter
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Hex - Decimal converter
You never know when you might need one of these.
Last edited by richmond62 on Sun May 01, 2016 11:53 am, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hex - Decimal converter
Any one for a spot of programming?
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hex - Decimal converter
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).
presenting everything in Hexadecimal (and on the left is all the work I had to do to hack
their document with Decimal numbers).
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hex - Decimal converter
Just like Tarzan; now swings both ways:
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Hex - Decimal converter
Aha; now I realised I was missing something.
- Attachments
-
- UNHEXXER.rev.zip
- 2.7 to 7.0.
- (23.25 KiB) Downloaded 230 times
-
- UNHEXXER.livecode.zip
- 7.0 and up.
- (23.24 KiB) Downloaded 232 times
-
- Posts: 57
- Joined: Mon Oct 28, 2013 1:23 pm
- Location: Dresden, Germany
Re: Hex - Decimal converter
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
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
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
-
- VIP Livecode Opensource Backer
- Posts: 138
- Joined: Wed Aug 26, 2009 7:42 pm
- Location: Randolph, MA USA
- Contact:
Re: Hex - Decimal converter
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
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.
Researchware, Inc.
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria