|
-
Mar 31st, 2004, 11:24 AM
#1
Thread Starter
yay gay
How to turn an integer into a binary string?
How can I WITHOUT USING THE VB COMPABILITY NAMESPACE get it's binary representation? For example : 3021 would turn into 101111001101
tks
\m/  \m/
-
Mar 31st, 2004, 12:55 PM
#2
Hi.
Something like this, should do it.
This uses a 16 bit value, hence the value of 15, but you can just as well use 31 instead of 15 to use a 32 bit value.
VB Code:
Dim S as String
Dim I as Integer
For I=15 To 0 Step -1
If (Value And 2^I)=2^I Then
S &= "1"
Else
S &= "0"
End If
Next
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Mar 31st, 2004, 01:01 PM
#3
I posted a function in this thread that converts signed long integers. Not sure what you'd need to do to modify it for .NET though.
http://www.vbforums.com/showthread.p...hreadid=282094
-
Apr 1st, 2004, 08:20 AM
#4
VB Code:
Dim val() As Integer = {1}
Dim x As New BitArray(val)
Dim strOut As String
For i As Integer = 0 To x.Count - 1
strOut &= IIf(x.Item(i), "1", "0")
Next
Debug.WriteLine(StrReverse(strOut))
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Apr 1st, 2004, 11:05 AM
#5
Frenzied Member
PT Exorcist, is this related to your thread where 4635 = 18,27? If so, you don't need to go through all that trouble
VB Code:
Dim port As Integer = 4635
MessageBox.Show(Decimal.Truncate(port / 256))
MessageBox.Show(port Mod 256)
-
Apr 1st, 2004, 11:48 AM
#6
Thread Starter
yay gay
You rule so much Ill try it now.
\m/  \m/
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
|