Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Hex overflow

TedTed Posts: 112Member
Is this really so??

?hex(1234567890)
499602D2

?hex(12345678901)
-> overflow

I need to convert up to 50 digits into hex values using VB6, but have not found any way around this yet.. Anyone?
«13

Comments

  • IDKIDK Posts: 1,784Member
    : Is this really so??
    :
    : ?hex(1234567890)
    : 499602D2
    :
    : ?hex(12345678901)
    : -> overflow
    :
    : I need to convert up to 50 digits into hex values using VB6, but have not found any way around this yet.. Anyone?
    :

    Use a baseconverter.
    It isn't so very hard to make...

    Happy coding wishes
    the one and only
    [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

  • DrMartenDrMarten Posts: 748Member
    : Is this really so??
    :
    : ?hex(1234567890)
    : 499602D2
    :
    : ?hex(12345678901)
    : -> overflow
    :
    : I need to convert up to 50 digits into hex values using VB6, but have not found any way around this yet.. Anyone?
    :
    ===========================================
    I was going to suggest you start with the CALCULATOR in WINDOWS and change the view the SCIENTIFIC.
    I've discovered a bug in it though!!
    Type in 99999999999999999999999999999999 ( 32 lots of 9 )
    Click on the HEX button it gives>>
    85ACEF80FFFFFFFF
    CLICK on the DEC button and you don't get the original number back!!

    So much for MicroSoft programmers!!
    ===================================

    I'm not getting the right result for 999,999 so i'll have to try harder.

    :-(


  • lionblionb Posts: 1,688Member ✭✭
    [b][red]This message was edited by lionb at 2006-1-30 12:34:57[/red][/b][hr]
    [b][red]This message was edited by lionb at 2006-1-30 11:10:41[/red][/b][hr]
    Dear Dr.Marten,
    Have you read the question? He said quote [Blue]I need to convert up to 50 digits into hex values [b]using VB6[/b][/blue] end quote. In orher words, he needs [b]programming code[/b] not tool.




  • iwilld0itiwilld0it Posts: 1,134Member
    [b][red]This message was edited by iwilld0it at 2006-1-30 12:44:23[/red][/b][hr]
    This is a very tough task, considering that Visual Basic or most languages for that matter, do not support a data type of that precision. Personally, I think it can not be done but it would be interesting to be proved wrong.

    Maybe this site will have some insight:

    http://www.cut-the-knot.org/binary.shtml

    (Has something written in javascript that you prob can translate to VB. You can view source of HTML page.)

    http://en.wikipedia.org/wiki/Binary_numeral_system

    Interesting info on Hex.




  • infidelinfidel Posts: 2,900Member
    : [b][red]This message was edited by iwilld0it at 2006-1-30 12:44:23[/red][/b][hr]
    : This is a very tough task, considering that Visual Basic or most languages for that matter, do not support a data type of that precision.

    I can't resist the opportunity to point out that Python can do this without blinking:

    >>> googol = 10 ** 100
    >>> googol
    10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L
    >>> hex(googol)
    '0x1249AD2594C37CEB0B2784C4CE0BF38ACE408E211A7CAAB24308A82E8F10000000000000000000000000L'



    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • TedTed Posts: 112Member
    Will this solution turn out right?

    Function myHex$(ByVal h$)

    Dim i%
    Dim t$, t1$

    While Len(h$)
    t1$ = Hex(Left$(h$, 10))
    t$ = t$ + t1$
    h$ = Mid$(h$, 11)
    Wend

    myHex$ = t$

    End Function

  • iwilld0itiwilld0it Posts: 1,134Member
    : Will this solution turn out right?
    :
    : Function myHex$(ByVal h$)
    :
    : Dim i%
    : Dim t$, t1$
    :
    : While Len(h$)
    : t1$ = Hex(Left$(h$, 10))
    : t$ = t$ + t1$
    : h$ = Mid$(h$, 11)
    : Wend
    :
    : myHex$ = t$
    :
    : End Function
    :
    :

    It started off good ...

    but I tried it w/

    12345678901234567890

    and got ...

    499602D2499602D2

    but when I use the scientific calculator that comes w/ windows it computes it as this hex ...

    AB54A98CEB1F0AD2

  • IDKIDK Posts: 1,784Member
    : : [b][red]This message was edited by iwilld0it at 2006-1-30 12:44:23[/red][/b][hr]
    : : This is a very tough task, considering that Visual Basic or most languages for that matter, do not support a data type of that precision.
    :

    I don't see where it's tough.

    Make a base converter!
  • DrMartenDrMarten Posts: 748Member
    : Is this really so??
    :
    : ?hex(1234567890)
    : 499602D2
    :
    : ?hex(12345678901)
    : -> overflow
    :
    : I need to convert up to 50 digits into hex values using VB6, but have not found any way around this yet.. Anyone?
    :

    '-------------START---OF---CODE------------------------------
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim number As Double
    Dim divResult As Double
    Dim index As Double
    Dim logResult As Double
    Dim char1 As Integer
    Dim outputChar As String
    Dim outputString As String = ""
    Dim remainder As Integer
    number = InputBox("Enter a number please", "Enter your number please")
    While number >= 0
    logResult = number Mod 16
    char1 = CInt(logResult)
    Select Case char1
    Case Is = 0
    outputChar = "0"
    Case Is = 1
    outputChar = "1"
    Case Is = 2
    outputChar = "2"
    Case Is = 3
    outputChar = "3"
    Case Is = 4
    outputChar = "4"
    Case Is = 5
    outputChar = "5"
    Case Is = 6
    outputChar = "6"
    Case Is = 7
    outputChar = "7"
    Case Is = 8
    outputChar = "8"
    Case Is = 9
    outputChar = "9"
    Case Is = 10
    outputChar = "A"
    Case Is = 11
    outputChar = "B"
    Case Is = 12
    outputChar = "C"
    Case Is = 13
    outputChar = "D"
    Case Is = 14
    outputChar = "E"
    Case Is = 15
    outputChar = "F"
    End Select
    outputString = outputChar & outputString
    number = Math.Round(number / 16)
    If number <= 1 Then Exit While
    End While
    If number = 1 Then
    TextBox1.Text = "1" & outputString
    Else
    TextBox1.Text = outputString
    End If

    TextBox1.AppendText(Chr(13) & Chr(10))
    End Sub

    '--------------------END---OF---CODE-------------------------------

    999,999 produces F424F with this code though. :-(
    This is 16 above the actual value of F423F.

    I may have another bash at this using the LOG10 function instead, i've tried variable type LONG too.

    Regards,

    Dr M.

    P.S. To lionb, I was giving a temporary answer before,like this one is, as it is not 100% perfect.



  • iwilld0itiwilld0it Posts: 1,134Member
    Ted is looking for something that can convert up to a 50 digit number into a hex ... i dont think that is possible w/ Visual Basic (unless there is some mystical voodoo I am not aware of.)

    The best base converter I found, can be downloaded here:

    http://www.freevbcode.com/ShowCode.Asp?ID=1671

    It can handle up to a 28 digit number.

    If anyone can do better, then i'll be extremely impressed :)
«13
Sign In or Register to comment.