|
-
May 11th, 2001, 02:25 PM
#1
Thread Starter
Fanatic Member
Quick Question ...
In the General forums, I attempted to help someone who was looking for a way to change a double into a binary string. I have one that works up to 2^31 or 999,999,999. Is there any possible way to convert numbers greater than that to binary? Any ideas would be appreciated.
I know, he should have posted here if he really wanted to know, but it's been bugging me for the past couple of days 
Thankee
-
May 11th, 2001, 02:55 PM
#2
Thread Starter
Fanatic Member
I found an answer on planet-source-code.com here it is (modified by me to be binary only and return the correct number of paired 1's and 0's) I didn't catch the original authors name, but kudos to him as well.
Code:
Function ConvertToBase(DecNumber As Double) As String
Dim ModBase As Double
Do
ModBase = CDbl(DecNumber - (Int(DecNumber / 2)) * 2)
DecNumber = Int(DecNumber / 2)
If ModBase > 9 Then ModBase = ModBase + 7
ConvertToBase = Chr(ModBase + 48) & ConvertToBase
Loop Until DecNumber = 0
If Len(ConvertToBase) / 2 <> Len(ConvertToBase) \ 2 Then ConvertToBase = "0" & ConvertToBase
End Function
-
May 29th, 2001, 11:17 AM
#3
Lively Member
To convert a big decimal number into a binary is not too difficult, but you will have problem to do that backward.
The input is a string, that contains the number (in VB, you can't use a number with - let's say - 300 digits)
1)
Then you have to check whether the number(string) is divisble by 2. You only have to check the last digit.
If this is true, the first digit of your binary number is 1, else, it's 0.
2)
Then, the problem appears, you'll have to divide this string by 2.
So, you need a loop, that does that for you.
If you managed to divide the number, goto 1) and repeat this until
the number is 0. (that means, the last division is 1/2 or 2/2).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|