am tring to conver the left number in the atached image to the on on the right but i recive overflow
http://bb.1asphost.com/pelegk2/333.GIf
how can i slove this problem?
thnaks i nadvance
peleg
Printable View
am tring to conver the left number in the atached image to the on on the right but i recive overflow
http://bb.1asphost.com/pelegk2/333.GIf
how can i slove this problem?
thnaks i nadvance
peleg
Unfortunately, that large of a number is too much for even a Long.
Singles and Doubles can hold it, but because they use significant digits, the value of the number gets changed.
With Single:
Entered 144614369260322395
Returned 144614366354866176
With Double:
Entered 144614369260322395
Returned 144614369260322400
My best suggestion would be to convert the hex into a String, and whenever you make comparisons, if you make any, just make sure the value it's being compared against gets put into CStr().
Strings can perform direct comparisons with number strings perfectly as far as I can see, so "500" < "600" will return True, "455" <= "300" will return False, "400" <> "400" will return False, etc.
i didnt execlly understamdnd you
i ned oo convert 1 of them to the other format before i can compre!
how will i do it?
Make the comparisons as strings.
Meaning, make both values being compared into Strings when you compare them, using the CStr() function if necessary.
Hi !
I'm working on that. Hope to present you a solution soon. 100 decimal digits are enough ?
Jonny Poet
Here are some converterfunctions I have done for u, working up to 100 decimal digits
Please test them. Hope that helps
Jonny Poet
Yea, but I think he has to compare long decimals against hex values !! so he has to convert one of them before he can compare.Quote:
Originally Posted by ChaosTheEternal
So I did some converters.
:wave: Jonny Poet
Hey Jonny you are great... Thanks for help.Quote:
Originally Posted by JonnyPoet
P.S : I love this site.... I think the best coding site on the planet
hey Joney it worked!
i need only 15 number length:)
thnaks alot great day and great weekd end
peleg
maybe u have the opposite:
from dec to hex?
VB already has that built in:
Hex(Number)
It returns the number as a hexadecimal String.
... unfortunately, Hex can't handle values larger than Longs.
You would have to do some manual conversion.
Yes I tried that, but putting in, the given number 144614369260322395 is changed to an format with exponent ( I dont know english expression ) 1446...E+17 something like that so its not really usable I think.Quote:
Originally Posted by ChaosTheEternal
I'll do that from a string-number like "1446..." into a hex string in the evening ( Its just now 3 PM in Vienna) so in some hours it should be done
Jonny Poet
Just one note here ... the above examples work because they the same length.. if you try "9" < "10" you get false.. because in text digit 1 is compared to Digit 1 then digit 2, 3.....Quote:
Originally Posted by ChaosTheEternal
In this case use format to add in leading 0's
Gremmy
Yes Gremmy you talked out of my soul. Yesterday I want to mention that, then I forgot. Today it was on my list to do that. You did :thumb:Quote:
Originally Posted by GremlinSA
BTW I just started to program the Long-Decimal-string to Binary and to Hex functions. Will be ready soon I hope.
For comparing strings, you could opt to check the lengths of them first, then the strings.
Code:If Len(strOne) = Len(strTwo) Then
If strOne > strTwo Then MsgBox "strOne is larger"
If strOne < strTwo Then MsgBox "strTwo is larger"
If strOne = strTwo Then MsgBox "strOne = strTwo"
Else
If Len(strOne) > Len(strTwo) Then MsgBox "strOne is larger"
If Len(strOne) < Len(strTwo) Then MsgBox "strTwo is larger"
End If
Tratatata...............
Here it is, have fun. :D
A compare Function is added too!
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.Quote:
Originally Posted by ChaosTheEternal
Jonny Poet
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:
Due to VB automatically getting rid of the leading zeroes, I tried:Code:Debug.Print CStr(00005)
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").Code:Private Sub Command1_Click()
Debug.Print CStr(CLng(Text1.Text))
End Sub
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 haveQuote:
Originally Posted by ChaosTheEternal
"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:
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
That methode is correct. So you have to add this in the beginning of your compare function and it will do its job.Quote:
Originally Posted by ChaosTheEternal
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.