Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert to hex ??
Message
From
22/07/2008 06:49:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
21/07/2008 21:24:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01332438
Message ID:
01333063
Views:
16
This message has been marked as a message which has helped to the initial question of the thread.
>Your suggestion works very well with positive number (90% of database) but negative numbers don't show the right result.
>eg : -77442022681 should show up as EDF81882E7. Your help will be appreciated. TIA
? longtohex(-77442022681)

Procedure longtohex
  Lparameters tnNumber
    Return Transform(m.tnNumber/(0xFFFFFFFF + 1) - IIF(m.tnNumber<0,1,0),'@0')+;
      RIGHT(Transform(m.tnNumber%(0xFFFFFFFF + 1),'@0'),8)
However I wouldn't trust VFP (more precisely to my own coding in VFP) with such big numbers. I would instead use a C FLL or C# COM component. ie: Here is a sample C# COM for such:
using System;
using System.Runtime.InteropServices;

namespace vfpHexUtil
{
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("cbVFPCOM.cbNumConverter")]
    [ComVisible(true)]
    public class cbNumConverter
    {
        public string I64ToHex(Int64 number)
        {
            return number.ToString("X").PadLeft(16,'0');
        }
    }
}
-You can write this code usign notepad (or better yet download C# express for free so you don't have to do all these manually from command line) and save as say as "mynumconverter.cs"
-Locate csc.exe (normal location is windows\Microsoft.Net\Framework\vXXXX)
-Create a key file first, compile to a dll and register:

sn -k myNumconverter.snk
csc /target:library /keyfile:myNumconverter.snk myNumconverter.cs
regasm myNumconverter.dll /codebase

Now you have COM Dll you can use it like:
o = createobject("cbVFPCOM.cbNumConverter")
myHexString = o.I64ToHex(-77442022681)
? m.myHexString
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform