|
-
May 6th, 2001, 05:57 PM
#1
How can I convert a decimal number to a binary number?
How can I convert a decimal number to a binary number? Do you know if there's the function I can find in VB?
Thank you for your help!
Best Regards,
Kevin Shen
Best Regards,
Kevin Shen
-
May 7th, 2001, 01:24 AM
#2
Re: How can I convert a decimal number to a binary number?
I don't think there is any function in VB, But I wrote function that do it.
Try it:
private Function DecimalToBinary(decNumber as Long) as string
Dim i as Long
Dim binNumber as string
binNumber = ""
i = 1
Do While decNumber > 0
If ((decNumber \ i) Mod 2) = 1 then
binNumber = "1" & binNumber
decNumber = decNumber - i
else
binNumber = "0" & binNumber
End If
i = i * 2
Loop
DecimalToBinary = binNumber
End Function
I hope it help you.
-
May 7th, 2001, 07:24 AM
#3
Re: How can I convert a decimal number to a binary number?
Here's a function that will convert any decimal number less than 256 to binary:
Function Decimal2Binary(TheNumber As Integer) As String
Dim TheBinaryNumber As String
Dim ThePosition As Integer
Dim iWork As Integer
TheBinaryNumber = "00000000"
If TheNumber < 256 Then
ThePosition = 128
For iWork = 1 To 8
If TheNumber >= ThePosition Then
Mid$(TheBinaryNumber, iWork, 1) = "1"
TheNumber = TheNumber - ThePosition
End If
ThePosition = ThePosition / 2
Next
End If
Decimal2Binary = TheBinaryNumber
End Function
Iouri Boutchkine
[email protected]
-
May 7th, 2001, 02:45 PM
#4
Re: How can I convert a decimal number to a binary number?
here's an article that has a routine that will go from any base number to any other base number and back again. http://www.codeguru.com/vb/articles/2137.shtml
hope it can help,
john
John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org
John Pirkey
MCSD (VB6)
http://www.stlvbug.org
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
|