我写了一个 Int 2 Hex 函数,想知道这是否是最好的方法
https://gist.github.com/kaayr1m/cacd3432b53fd854b0de
还有其他方法可以做到这一点吗?
' @param intValue positive integers from 0 onwards
function IntHexString(intValue as Integer) as String
this = {}
this.hexString = function(int) as String
num = int/16.0
remainder = (num mod 1) * 16.0
result = fix(num)
if remainder > 15
hex = m.hexString(remainder)
else
hex = m.determineHex(remainder)
end if
if (result > 0) hex = m.hexString(result) + hex
retun hex
end function
' 0 --> 15
this.determineHex = function(int) as String
if int = 15 then return "F"
if int = 14 then return "E"
if int = 13 then return "D"
if int = 12 then return "C"
if int = 11 then return "B"
if int = 11 then return "A"
return int
end function
return this.hexString(intValue)
end function