Hex overflow

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?
«1

Comments

  • : 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]

  • : 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.

    :-(


  • [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.




  • [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.




  • : [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]

  • 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

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

  • : : [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!
  • : 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.



  • 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 :)
  • : 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 :)
    :

    Why is limited to 28 digits?

    If you make it pass a string, then it could have as large number as possible.

    I think I've made something like this in QBASIC...
  • : : 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.

    Dear Dr M,;-)

    In VB.NET you can replace all the above by this
    [code]
    Me.TextBox1.Text = Hex(1234567890119191919)
    [/code]
    with out any problem
  • It is true that you can store any number you want as a string, but in order for you to calculate the Hex, that string has to eventually be converted into an actual number.

    I have not found an algorithm that lets you analyze the number as a string and calculate the hex.

    Your question is: Why is limited to 28 digits?

    Well the largest data type in VB6 is the Decimal data-type, which you can not directly create to start w/. You have to store a very large number in a Variant.

    : : 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 :)
    : :
    :
    : Why is limited to 28 digits?
    :
    : If you make it pass a string, then it could have as large number as possible.
    :
    : I think I've made something like this in QBASIC...
    :

  • [b][red]This message was edited by lionb at 2006-2-1 10:17:29[/red][/b][hr]
    [b][red]This message was edited by lionb at 2006-2-1 9:23:8[/red][/b][hr]
    : : 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
    :
    :
    It's happened because 499602D2499602D2 is not actually [b][red]real[/red][/b] HEX number for 12345678901234567890. This function devided h$ string in 2 parts then converted each of them to HEX and then concatenated them together again. So result 499602D2499602D2 is actually contains of two [b]concatenated strings[/b] - 499602D2 (HEX for the first decimal part 1234567890) & 499602D2 (HEX for second decimal part 1234567890).




  • [b][red]This message was edited by IDK at 2006-2-1 9:52:35[/red][/b][hr]
    : It is true that you can store any number you want as a string, but in order for you to calculate the Hex, that string has to eventually be converted into an actual number.
    :
    : I have not found an algorithm that lets you analyze the number as a string and calculate the hex.
    :
    : Your question is: Why is limited to 28 digits?
    :
    : Well the largest data type in VB6 is the Decimal data-type, which you can not directly create to start w/. You have to store a very large number in a Variant.
    :
    : : : 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 :)
    : : :
    : :
    : : Why is limited to 28 digits?
    : :
    : : If you make it pass a string, then it could have as large number as possible.
    : :
    : : I think I've made something like this in QBASIC...
    : :
    :
    :

    Use DrMarten code and make a string type with devide and remainder. It isn't hard. I have made exactly this in QBASIC...

    Another way would be to make a double or tripple long type. It would be a little faster...

    EDIT: Could someone tell me what 10^16 is in hex?
Sign In or Register to comment.

Howdy, Stranger!

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

Categories