Dear All
I like to take an integer value such as 3000 and convert to binary mode such as "3000=101110111000" and compare every bit and find-out which of the bits is set to "1" and which of the bits set to "0"
Many Thanks for any reply
salih
Printable View
Dear All
I like to take an integer value such as 3000 and convert to binary mode such as "3000=101110111000" and compare every bit and find-out which of the bits is set to "1" and which of the bits set to "0"
Many Thanks for any reply
salih
Try this to get you started.
VB Code:
Dim i As Integer = 3000 Dim str As String = Convert.ToString(i, 2) Debug.WriteLine(str)
Here's the rest of what you want. I'm not sure that the For loop is the smartest way to do it, but its all I can think of at the moment...
VB Code:
Dim i As Integer = 3000 Dim str As String = Convert.ToString(i, 2) Debug.WriteLine(str) Dim find As Integer For find = Len(str) To 1 Step -1 If Mid(str, find, 1) = "1" Then Debug.WriteLine("Bit " & Len(str) - find + 1 & " is set.") End If Next
You should look into the BitVector32 class.