VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



BigDecToHex

by Inon Henig (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Converting decimal value to hexadecimal WITHOUT! using the VB functions or mod (which are limited to long data type value), therefore the function can handle BIG numbers, untill 15,000,000,000,000,000 (1.5E+16).

Inputs
decimal value
Code Returns
hexadecimal value
Side Effects
The functions might not be accurate beyond 15,000,000,000,000,000 (1.5E+16).

Rate BigDecToHex

Public Function BigDecToHex(ByVal DecNum) As String
  ' This function is 100% accurate untill 15,000,000,000,000,000 (1.5E+16)
  
  Dim NextHexDigit As Double
  Dim HexNum As String
  
  HexNum = ""
  While DecNum <> 0
    NextHexDigit = DecNum - (Int(DecNum / 16) * 16)
    
    If NextHexDigit < 10 Then
      HexNum = Chr(Asc(NextHexDigit)) & HexNum
    Else
      HexNum = Chr(Asc("A") + NextHexDigit - 10) & HexNum
    End If
    
    DecNum = Int(DecNum / 16)
  Wend
  If HexNum = "" Then HexNum = "0"
  BigDecToHex = HexNum
End Function

Download this snippet    Add to My Saved Code

BigDecToHex Comments

No comments have been posted about BigDecToHex. Why not be the first to post a comment about BigDecToHex.

Post your comment

Subject:
Message:
0/1000 characters