Jump to content

UDF _HexLen


Mikon
 Share

Recommended Posts

i thougth this could be usefull for someone

Func _HexLen($Number)
    If Not IsNumber($Number) Then
        SetError(1)
        Return 0
    ElseIf $Number = 0 Then
        Return 1
    Else
        If $Number < 0 Then $Number = $Number * -1
        Return Int(Log($Number)/Log(16))+1
    EndIf
EndFunc

example:

$aNumber = Random(1, 1000);you dont know the value of $aNumber and so you dont know the second parameter for the Hex-function
$Hex = Hex($aNumber, _HexLen($aNumber))
MsgBox(0, "Example for " & $aNumber, $Hex)

you can modify this with replacing the 16 in line 9 with a 2 for calculating the length of a binary number (just for example)

Mikon

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...