【问题标题】:how can i make a hex string from integer value in Brightscright?如何从 Brightscright 中的整数值制作十六进制字符串?
【发布时间】:2015-07-29 04:43:53
【问题描述】:

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

【问题讨论】:

    标签: hex decimal roku brightscript


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-04-28
      • 2019-07-27
      • 2017-08-12
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2017-06-16
      • 2010-10-25
      相关资源
      最近更新 更多