如何在 Brightscright 中从整数值生成十六进制字符串?

how can i make a hex string from integer value in Brightscright?

我写了一个 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

是的,有更好的方法 - 使用 stri(val, radix),像这样:

BrightScript Debugger> ? &h12abcdef
 313249263
BrightScript Debugger> ? stri(313249263, 16)
12abcdef