kenbrueck
13 years agoVisitor
Convert Int to Hex?
Is there a simple way to convert an integer to hex in Brightscript? For example, given 255 it would return FF (or some similar form, e.g. 0xFF, 0x0000FF, etc.)
' * Convert an integer to a hex string *
function ConvertINTtoHEX(num as integer) as string
return rdINTtoBA(num).toHexString()
end function
' * Convert an integer to a (4 byte) roByteArray *
function fastINTtoBA(num as integer) as object
ba = CreateObject("roByteArray")
ba.setresize(4, false)
i% = num
ba[3] = i%
i% = i% / 256 : ba[2] = i% ' using % auto converts float from division to int
i% = i% / 256 : ba[1] = i% ' then assigning to bytes auto truncates (AND &h0ff)
i% = i% / 256 : ba[0] = i%
return ba
end function