- Joined
- Oct 12, 2011
- Messages
- 3,449
guys, I'm currently wondering in making converter from hexadecimals to decimals.. here is the code I made
it's working perfectly but I think there must be simple way, or maybe not, not sure yet. please help me to make this converter perfect/optimized.. thnks
after finishing this one I'm also will make the converter from decimals to hexadecimals as well..
why I need this? my idea is to make gradient engine which able to produce text with gradient colors
Now, the converter from decimals to hexadecimals has done here is the code
JASS:
function X2I takes string hex returns integer
local string hexas = "0123456789abcdef"
local string sub1
local string sub2
local integer i = StringLength(hex)
local integer i2
local integer m = 0
local integer int = 0
loop
exitwhen i == 0
set i2 = 0
set sub1 = SubString(hex, i-1, i)
loop
set i2 = i2 + 1
set sub2 = SubString(hexas, i2-1, i2)
if sub1 == sub2 or sub1 == StringCase(sub2, true)then
set int = int + 15 * m * (i2-1) + i2 - 1
endif
exitwhen i2 == 16
endloop
set m = m + 1
set i = i - 1
endloop
return int
endfunction
it's working perfectly but I think there must be simple way, or maybe not, not sure yet. please help me to make this converter perfect/optimized.. thnks
after finishing this one I'm also will make the converter from decimals to hexadecimals as well..
why I need this? my idea is to make gradient engine which able to produce text with gradient colors
Now, the converter from decimals to hexadecimals has done here is the code
JASS:
function I2X takes integer int returns string
local string hexas = "0123456789abcdef"
local string hex = ""
local integer dev
loop
if int > 15 then
set dev = int - (int / 16) * 16
set int = int / 16
set hex = SubString(hexas, dev, dev + 1) + hex
else
set hex = SubString(hexas, int, int + 1) + hex
return hex
endif
endloop
return hex
endfunction
Last edited: