Solved

# Changing Hex to Decimal Long

Posted on 2003-02-25
Medium Priority
230 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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month13 days, 18 hours left to enroll