我编写了一个Int 2 Hex函数,并想知道这是否是最好的方法
有没有其他方法可以做到这一点?
' @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
答案 0 :(得分:1)
是的,还有更好的方法 - 使用stri(val, radix),如下所示:
BrightScript Debugger> ? &h12abcdef
313249263
BrightScript Debugger> ? stri(313249263, 16)
12abcdef