Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hex overflow Posted by Ted on 30 Jan 2006 at 5:31 AM
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?
Report
Re: Hex overflow Posted by IDK on 30 Jan 2006 at 9:06 AM
: 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
Niklas Ulvinge aka IDK

Report
Re: Hex overflow Posted by iwilld0it on 31 Jan 2006 at 11:54 AM
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 :)
Report
Re: Hex overflow Posted by IDK on 31 Jan 2006 at 12:45 PM
: 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...
Report
Re: Hex overflow Posted by iwilld0it on 1 Feb 2006 at 7:57 AM
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...
:

Report
Re: Hex overflow Posted by IDK on 1 Feb 2006 at 9:39 AM
This message was edited by IDK at 2006-2-1 9:52:35

: 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?
Report
Re: Hex overflow Posted by iwilld0it on 1 Feb 2006 at 11:57 AM
Well if it is easy, then why not impress us w/ an example, because I've tried real hard to figure out a solution :)

It has to be able to HEX a 50 digit decimal number.
Report
Re: Hex overflow Posted by IDK on 1 Feb 2006 at 12:37 PM
: Well if it is easy, then why not impress us w/ an example, because I've tried real hard to figure out a solution :)
:
: It has to be able to HEX a 50 digit decimal number.
:

OK, here's actually some asm I did. Becouse it was so easy...


xor bx,bx
mov bx,data
mov cl,4
mov ah, 02h

start:
mov dh,[bx]
mov dl,dh
and dl,1111b
mov di,dl
mov dl,[hexnum+di]
int 21h
mov dl,dh
shr dl,cl
inc bx
mov di,dl
mov dl,[hexnum+di]
int 21h

cmp bx,endofData
jb start

mov ax,4C00h
int 21h

hexnum: db "0123456789ABCDEF"
data:   db 212,244,1,121
endofData:


I got some other funcs for string devide, but I can't find them.
Report
Re: Hex overflow Posted by iwilld0it on 1 Feb 2006 at 1:07 PM
It's beautiful, accept I do not understand a lick of assembly :(

Now question is, can you translate it to VB?


: : Well if it is easy, then why not impress us w/ an example, because I've tried real hard to figure out a solution :)
: :
: : It has to be able to HEX a 50 digit decimal number.
: :
:
: OK, here's actually some asm I did. Becouse it was so easy...
:
:
: 
: xor bx,bx
: mov bx,data
: mov cl,4
: mov ah, 02h
: 
: start:
: mov dh,[bx]
: mov dl,dh
: and dl,1111b
: mov di,dl
: mov dl,[hexnum+di]
: int 21h
: mov dl,dh
: shr dl,cl
: inc bx
: mov di,dl
: mov dl,[hexnum+di]
: int 21h
: 
: cmp bx,endofData
: jb start
: 
: mov ax,4C00h
: int 21h
: 
: hexnum: db "0123456789ABCDEF"
: data:   db 212,244,1,121
: endofData:
: 

:
: I got some other funcs for string devide, but I can't find them.
:

Report
Re: Hex overflow Posted by DrMarten on 30 Jan 2006 at 9:46 AM
: 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.




Report
Re: Hex overflow Posted by lionb on 30 Jan 2006 at 11:09 AM
This message was edited by lionb at 2006-1-30 12:34:57

This message was edited by lionb at 2006-1-30 11:10:41

Dear Dr.Marten,
Have you read the question? He said quote I need to convert up to 50 digits into hex values using VB6 end quote. In orher words, he needs programming code not tool.




Report
Re: Hex overflow Posted by iwilld0it on 30 Jan 2006 at 12:44 PM
This message was edited by iwilld0it at 2006-1-30 12:44:23

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.




Report
Re: Hex overflow Posted by infidel on 30 Jan 2006 at 2:13 PM
: This message was edited by iwilld0it at 2006-1-30 12:44:23

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



infidel

$ select * from users where clue > 0
no rows returned


Report
Re: Hex overflow Posted by IDK on 31 Jan 2006 at 8:28 AM
: : This message was edited by iwilld0it at 2006-1-30 12:44:23

: : 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!
Report
Re: Hex overflow Posted by Ted on 31 Jan 2006 at 3:26 AM
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

Report
Re: Hex overflow Posted by iwilld0it on 31 Jan 2006 at 7:44 AM
: 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

Report
Re: Hex overflow Posted by lionb on 1 Feb 2006 at 8:51 AM
This message was edited by lionb at 2006-2-1 10:17:29

This message was edited by lionb at 2006-2-1 9:23:8

: : 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 real 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 concatenated strings - 499602D2 (HEX for the first decimal part 1234567890) & 499602D2 (HEX for second decimal part 1234567890).




Report
I have this code so far>> written in VB.net though. Posted by DrMarten on 31 Jan 2006 at 11:26 AM
: 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.



Report
Re: I have this code so far>> written in VB.net though. Posted by lionb on 31 Jan 2006 at 1:25 PM
: : 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
   Me.TextBox1.Text = Hex(1234567890119191919)

with out any problem
Report
Re: Hex overflow. Note to everyone in this subject / thread. Posted by DrMarten on 1 Feb 2006 at 12:37 PM
I am going to look at the Hex function ( mentioned elsewhere here ) but i feel i may need to mess with maths using long strings.

With the right code you can do maths on the numbers within strings of ANY length. I've done this ages ago to multiply two long numbers together. You are not limited to 32 digits with a 32 bit processor!!
You could do 1024 bit maths or more ( provided your program can use 1024 character strings ).

Even if this were the limit you can CARRY with your "STRING MATHS" to another string. Just think about the way you do maths on paper by hand and make a computer do the same.

I may tackle this again before Friday but in the mean time i need to do a WEB SITE project for my HND course on university as an in-course-assessment ( like homework ).

My next approach may be to divide by the numbers which are powers of 16 like 16^0,16^1,16^2,16^3 etc, but in a reverse fashion, subtracting the number from the original number to be converted. I would start with>>

16^x where x<=numberToBeConverted and is the highest power of 16.
Feel free to start please....i need to get on with my web site.


Regards,

Dr M.

Report
Re: Hex overflow. Note to everyone in this subject / thread. Posted by iceburn_tuga on 17 May 2007 at 10:24 AM
: With the right code you can do maths on the numbers within strings
: of ANY length. I've done this ages ago to multiply two long numbers
: together. You are not limited to 32 digits with a 32 bit processor!!
: You could do 1024 bit maths or more ( provided your program can use
: 1024 character strings ).

Well I've done just that... Also needed hex with 16^15 values.

Here is the code... a lot messy and names in portuguese/spanish. Hope it saves someone a lot of work :)

Public Function Myhex(entrada) As String
    Dim valor As String
    Dim c As Integer
    Dim resultado As String
    Dim vc As String
    Dim i As Integer
    valor = entrada
    For i = 16 To 0 Step -1
        vc = potencia(16, i)
        c = dividir(valor, vc)
        resultado = resultado & myhexchar(c)
        If c > 0 Then
            valor = subtrair(valor, multiplicar(vc, Trim(Val(c))))
        End If
    Next i
    While Left$(resultado, 1) = "0" And Len(resultado) > 1
            resultado = Mid$(resultado, 2, Len(resultado) - 1)
    Wend
    Myhex = resultado
End Function
Public Function myhexchar(ent) As String
    Dim res As String
    Select Case ent
        Case 0 To 9: res = Trim(Str(ent))
        Case 10 To 15: res = UCase(Chr$(ent + 87))
    End Select
    myhexchar = res
End Function
Function dividir(dividendo As String, divisor As String) As Integer
    Dim ress As Integer
    Dim mult As String
    ress = 0
    Do
        ress = ress + 1
        mult = multiplicar(divisor, Trim(Val(ress)))
    Loop While Not (maiorque(mult, dividendo))
    dividir = ress - 1
End Function
Function maiorque(x1 As String, x2 As String) As Boolean
    If Len(x1) > Len(x2) Then
        maiorque = True
        Exit Function
    End If
    
    If Len(x2) > Len(x1) Or x1 = x2 Then
        maiorque = False
        Exit Function
    End If
    
    For i = 1 To Len(x1)
        If Asc(Mid$(x1, i, 1)) < Asc(Mid$(x2, i, 1)) Then
            maiorque = False
            Exit Function
        ElseIf Asc(Mid$(x1, i, 1)) > Asc(Mid$(x2, i, 1)) Then
            maiorque = True
            Exit Function
        End If
    Next i
    
    maiorque = True
    
End Function


Function subtrair(maior As String, menor As String) As String
    Dim resultado As String
    Dim vienen As Integer
    Dim x, y As Integer
    Dim i As Integer
    vienen = 0
    For i = 1 To Len(maior)
        x = posicion(maior, i)
        y = posicion(menor, i) + vienen
        If y > x Then
            vienen = 1
            x = x + 10
        Else
            vienen = 0
        End If
        resultado = Trim(Val(x - y)) & resultado
    Next i
    While Left$(resultado, 1) = "0" And Len(resultado) > 1
            resultado = Mid$(resultado, 2, Len(resultado) - 1)
    Wend
    subtrair = resultado
End Function
Function potencia(base As Integer, expoente As Integer) As String
    Dim base_string As String
    Dim temp As String
    base_string = Trim(Str(base))
    temp = "1"
    If expoente = 0 Then GoTo final
    For i = 1 To expoente
        temp = multiplicar(temp, base_string)
    Next i
final:
    potencia = temp
End Function
Function multiplicar(xxx As String, yyy As String) As String
Dim a As String
Dim b As String
Dim c As String
Dim linea(100) As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim tmp As Integer
Dim vienen As Integer
Dim resultado As String
a = xxx
b = yyy
If Len(b) > Len(a) Then
    c = a
    a = b
    b = c
End If
For i = 1 To Len(b)
    linea(i) = String(i - 1, "0")
    vienen = 0
    For j = 1 To Len(a)
        tmp = posicion(b, i) * posicion(a, j) + vienen
        vienen = tmp \ 10
        linea(i) = Trim(Str(tmp Mod 10)) & linea(i)
    Next j
    If vienen > 0 Then linea(i) = Trim(Str(vienen)) & linea(i)
Next i
vienen = 0
For i = 1 To Len(b) + Len(a)
    tmp = vienen
    For j = 1 To Len(a)
        tmp = tmp + posicion(linea(j), i)
    Next j
    vienen = tmp \ 10
    resultado = Trim(Str(tmp Mod 10)) & resultado
Next i
If Left$(resultado, 1) = "0" Then
    resultado = Mid$(resultado, 2, Len(resultado) - 1)
End If
multiplicar = resultado
End Function
Function posicion(z As String, x As Integer) As Integer
    If x > Len(z) Then
        posicion = 0
    Else
        posicion = Val(Mid$(z, Len(z) - x + 1, 1))
    End If
End Function

Report
Re: Hex overflow. Note to everyone in this subject / thread. Posted by BitByBit_Thor on 17 May 2007 at 12:29 PM
: Well I've done just that... Also needed hex with 16^15 values.
:
: Here is the code... a lot messy and names in portuguese/spanish.
: Hope it saves someone a lot of work :)
:

I glanced it over for a bit.

Looks fairly ok to me, but it's a bit hard(er) to understand for us that don't speak spanish.
Code-technically, it could (I think) use a couple of optimizations for speed but it looks like it'll work!
So if you're just interested in doing a couple of calculations with bigger numbers than usual than it looks good.
If you're however doing things like finding Prime Numbers of huge size then I think there is need for optimization.

Just out of interest... this Thread is 14 months old. How did you ever come across it? :P

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
Report
Re: Hex overflow. Note to everyone in this subject / thread. Posted by iceburn_tuga on 18 May 2007 at 1:03 AM
: Code-technically, it could (I think) use a couple of optimizations
: for speed but it looks like it'll work!

I would be happy to know you'r suggestions.

: Just out of interest... this Thread is 14 months old. How did you
: ever come across it? :P

I needed a 16^15 hex conversor in VB6. This thread was the 3rd result in googling "vb6 hex overflow". I though it could help someone with the same problem.

: Looks fairly ok to me, but it's a bit hard(er) to understand for us
: that don't speak spanish.

Here's a "translation".I think it's right (Find & Replace)... Haven't test it.

Public Function Myhex(input_value) As String
    Dim value As String
    Dim c As Integer
    Dim result As String
    Dim vc As String
    Dim i As Integer
    value = input_value
    For i = 16 To 0 Step -1
        vc = my_power(16, i)
        c = divide(value, vc)
        result = result & myhexchar(c)
        If c > 0 Then
            value = subtract(value, multiply(vc, Trim(Val(c))))
        End If
    Next i
    While Left$(result, 1) = "0" And Len(result) > 1
            result = Mid$(result, 2, Len(result) - 1)
    Wend
    Myhex = result
End Function
Public Function myhexchar(ent) As String
    Dim res As String
    Select Case ent
        Case 0 To 9: res = Trim(Str(ent))
        Case 10 To 15: res = UCase(Chr$(ent + 87))
    End Select
    myhexchar = res
End Function
Function divide(dividend As String, divisor As String) As Integer
    Dim ress As Integer
    Dim mult As String
    ress = 0
    Do
        ress = ress + 1
        mult = multiply(divisor, Trim(Val(ress)))
    Loop While Not (greaterthan(mult, dividend))
    divide = ress - 1
End Function
Function greaterthan(x1 As String, x2 As String) As Boolean
    If Len(x1) > Len(x2) Then
        greaterthan = True
        Exit Function
    End If
    
    If Len(x2) > Len(x1) Or x1 = x2 Then
        greaterthan = False
        Exit Function
    End If
    
    For i = 1 To Len(x1)
        If Asc(Mid$(x1, i, 1)) < Asc(Mid$(x2, i, 1)) Then
            greaterthan = False
            Exit Function
        ElseIf Asc(Mid$(x1, i, 1)) > Asc(Mid$(x2, i, 1)) Then
            greaterthan = True
            Exit Function
        End If
    Next i
    
    greaterthan = True
    
End Function


Function subtract(minuend As String, subtrahend As String) As String
    Dim result As String
    Dim carried As Integer
    Dim x, y As Integer
    Dim i As Integer
    carried = 0
    For i = 1 To Len(minuend)
        x = position(minuend, i)
        y = position(subtrahend, i) + carried
        If y > x Then
            carried = 1
            x = x + 10
        Else
            carried = 0
        End If
        result = Trim(Val(x - y)) & result
    Next i
    While Left$(result, 1) = "0" And Len(result) > 1
            result = Mid$(result, 2, Len(result) - 1)
    Wend
    subtract = result
End Function
Function my_power(base As Integer, exponent As Integer) As String
    Dim base_string As String
    Dim temp As String
    base_string = Trim(Str(base))
    temp = "1"
    If exponent = 0 Then GoTo final
    For i = 1 To exponent
        temp = multiply(temp, base_string)
    Next i
final:
    my_power = temp
End Function
Function multiply(xxx As String, yyy As String) As String
Dim a As String
Dim b As String
Dim c As String
Dim line(100) As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim tmp As Integer
Dim carried As Integer
Dim result As String
a = xxx
b = yyy
If Len(b) > Len(a) Then
    c = a
    a = b
    b = c
End If
For i = 1 To Len(b)
    line(i) = String(i - 1, "0")
    carried = 0
    For j = 1 To Len(a)
        tmp = position(b, i) * position(a, j) + carried
        carried = tmp \ 10
        line(i) = Trim(Str(tmp Mod 10)) & line(i)
    Next j
    If carried > 0 Then line(i) = Trim(Str(carried)) & line(i)
Next i
carried = 0
For i = 1 To Len(b) + Len(a)
    tmp = carried
    For j = 1 To Len(a)
        tmp = tmp + position(line(j), i)
    Next j
    carried = tmp \ 10
    result = Trim(Str(tmp Mod 10)) & result
Next i
If Left$(result, 1) = "0" Then
    result = Mid$(result, 2, Len(result) - 1)
End If
multiply = result
End Function
Function position(z As String, x As Integer) As Integer
    If x > Len(z) Then
        position = 0
    Else
        position = Val(Mid$(z, Len(z) - x + 1, 1))
    End If
End Function

Report
Re: Hex overflow. Note to everyone in this subject / thread. Posted by BitByBit_Thor on 18 May 2007 at 4:24 AM
: : Code-technically, it could (I think) use a couple of optimizations
: : for speed but it looks like it'll work!
:
: I would be happy to know you'r suggestions.
:

Well for values up to 16^15 it should have quite good peformance (relatively speaking).
I am currently also developing a Big Number library, only then for ridiculously big numbers. However, I'm not really making it from a practical point of view, but more for fun and to challenge myself to get as optimized code as possible for VERY BIG numbers :) The code I have written should perform quite well when the numbers are 10^20 +. But like I said: there is probably very little practical need to do such a thing ;)

I'd share some of my thoughts with you, but I can't yet be sure of the code. I haven't thoroughly tested it yet.

I might make another reply with some thoughts I had, but I don't think your code needs any of it. It's quite good.

:
: I needed a 16^15 hex conversor in VB6. This thread was the 3rd
: result in googling "vb6 hex overflow". I though it could help
: someone with the same problem.
:

Yeah sure :) Usually, bumping is a bad thing, but in this case I think it's quite ok to do so.

:
: Here's a "translation".I think it's right (Find & Replace)...
: Haven't test it.
:

Ahh helps :) Makes the code faster to read

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.