Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Changing Hex to Decimal Long

Posted on 2003-02-25
Medium Priority
240 Views
I have a hex string a1="FFFFFF" (24 bits)
I want to change it to decimal hence i use:

dec=CLng("&h" & a1)
this will return dec=16,777,215

This is fine.

Right now, I want to increase a1 to a 32 bit string
a1="FFFFFFFF"

doing the same thing above will return dec=-1,
Is there anyway, I can return the decimal value of FFFFFFFF=4,294,967,295???
0
Question by:VivienW

LVL 7

Expert Comment

ID: 8022495
You cant have unsigned longs in VB, so try single or double and round to nearest int.
0

LVL 4

Accepted Solution

TigerZhao earned 90 total points
ID: 8022716
Private Const DBL_UNSIGNED_BIT31        As Double = 2147483648#    '&H80000000
Function UnsignedLong(ByVal SignedLong As Long) As Double
If SignedLong < 0 Then
UnsignedLong = DBL_UNSIGNED_BIT31 + (SignedLong And &H7FFFFFFF)
Else
UnsignedLong = SignedLong
End If
End Function

?UnsignedLong(&HFFFFFFFF)
4294967295
0

LVL 1

Expert Comment

ID: 8024035
there is a simple solution since the source you provided is a hex string:

'begin

a1="FFFFFFFF"

dim p1 as double
'assign p1 the right 4 digits, i.e: p1=&HFFFF
p1=clng("&H" & right(a1,4))

dim p2 as double
'in c++, this should be done as p2<<4
p2=p1*(2^16)

dim dec as double
'add p1 and p2 to get the result
dec=p2+p1

'that's it,good luck!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
###### Suggested Courses
Course of the Month11 days, 16 hours left to enroll