?
Solved

Changing Hex to Decimal Long

Posted on 2003-02-25
3
Medium Priority
?
230 Views
Last Modified: 2010-05-01
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
Comment
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
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

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

Accepted Solution

by:
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

by:Belfry
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question