# converting very big numbers from hex to dec

Show 50 post(s) from this thread on one page
Page 2 of 2 First 12
• December 15th, 2005, 03:25 PM
JonnyPoet
Re: converting very big numbers from hex to dec
Tratatata...............

Here it is, have fun. :D

A compare Function is added too!
• December 15th, 2005, 03:39 PM
JonnyPoet
Re: converting very big numbers from hex to dec
Quote:

Originally Posted by ChaosTheEternal
Code:

```...         If Len(strOne) > Len(strTwo) Then MsgBox "strOne is larger"         If Len(strOne) < Len(strTwo) Then MsgBox "strTwo is larger" ...```

Hey Chaos ! Try compare string "00005" with "70" and you will see its not working like that in mathematical strings, because in that case "00005" is longer but value is less ! But dont worry. it was basically your idea of comparing strings that I used to figure out the functions in my zipfile.

Jonny Poet
• December 15th, 2005, 03:53 PM
ChaosTheEternal
Re: converting very big numbers from hex to dec
If you import a number into a String (such as via CStr() or some custom method), there would be no leading zeroes. So it would work.

My intent for that was on that line of thinking.

Since you can't even try:
Code:

`Debug.Print CStr(00005)`
Due to VB automatically getting rid of the leading zeroes, I tried:
Code:

```Private Sub Command1_Click()     Debug.Print CStr(CLng(Text1.Text)) End Sub```
I entered various numbers with a lot of trailing zeroes (like 00000006579) and only got the necessary value output (i.e. "6579", instead of "00000006579").
• December 15th, 2005, 05:52 PM
JonnyPoet
Re: converting very big numbers from hex to dec
Quote:

Originally Posted by ChaosTheEternal
If you import a number into a String (such as via CStr() or some custom method), there would be no leading zeroes. So it would work.
My intent for that was on that line of thinking.
Since you can't even try:
Code:

`Debug.Print CStr(00005)`
Due to VB automatically getting rid of the leading zeroes, I tried:
Code:

```Private Sub Command1_Click() Debug.Print CStr(CLng(Text1.Text)) End Sub```
I entered various numbers with a lot of trailing zeroes (like 00000006579) and only got the necessary value output (i.e. "6579", instead of "00000006579").

I understand what you are talking about but think - you have long strings of numbers to transcode so you cannot use CLng() you cannot even change the string into a value you have to add or subtract digit by digit and in that way you may get some leading zeros for example if you have
"12378934567" - "12324512455" or something like that you get "00054422112" and if you dont want to have trailing zeros you have to cut them away digit by digit from left to right until the digitvalue is > then 0.

If you try to do such a convert function you will see it will never work CStr(CLng(Text1.Text)) when Text1.Text exceeds the maxvalues of a long. Additional : You cannot compare a Hex-Value -string with a Decimal-Value-string that leads to nothing,so you have to transcode one of them, you see ? ;)

Jonny Poet :wave:
• December 16th, 2005, 08:20 AM
ChaosTheEternal
Re: converting very big numbers from hex to dec
Firstly, I was using CStr(CLng()) as an example that trying to put a number in with leading zeroes removes those zeroes automatically, as long as it is actually a number somewhere in there. Not as what you would actually do.

Secondly, it's comparisons. No addition or subtraction was required for his issue.

I know if you were to put the numbers in Strings and had to perform some mathematics on them, you would need to split up the whole number and do digit by digit comparisons, then piece the number to what it would really equal, and then optionally put it back into the String.

Doing anything beyond addition or subtraction would be a bit more difficult. Multiplication would be a lot easier than division (though for division, I would guess a lot of Modulus division would be involved).

And it's not hard to remove leading zeros from a String if you would manage to get them.
Code:

```Do Until Left(strNumber, 1) <> "0"     strNumber = Right(strNumber, Len(strNumber) - 1) Loop```
• December 16th, 2005, 02:23 PM
JonnyPoet
Re: converting very big numbers from hex to dec
Quote:

Originally Posted by ChaosTheEternal
...
Code:

```Do Until Left(strNumber, 1) <> "0" strNumber = Right(strNumber, Len(strNumber) - 1) Loop```

That methode is correct. So you have to add this in the beginning of your compare function and it will do its job.

The best to understand the problem is, if you look into the working code I did. Then you will see what I'm talking about. Basically is.. You cannot directly compare a string which holds a hexadecimal with a string which holds a decade value, for finding out which number is bigger. You need to transform one of them before you compare. I think you agree on that. ;)

For transformation I needed addition, subtraction and exponents-of-two and comparing-values-in stringform functions, all having the values in form of strings. And for comparing you can do a) removing trailing zeros or b) adding trailng zeros to get same string length before comparing, because you dont know what you will get as a result of transformation process. The result may or may not have some trailing zeros in the resultstring.

And the basic idea how to get it done, for really big values was to calculate all during holding the values as a string. And this simple idea, which I followed my buddy, was yours and thats what counts. :thumb:

Jonny Poet
PS.: Really Big things are always simple.
Show 50 post(s) from this thread on one page
Page 2 of 2 First 12