Results 1 to 4 of 4

Thread: Comparison binary in .NET

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    ENGLAND
    Posts
    38

    Comparison binary in .NET

    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
    sa

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Try this to get you started.

    VB Code:
    1. Dim i As Integer = 3000
    2.         Dim str As String = Convert.ToString(i, 2)
    3.         Debug.WriteLine(str)
    This world is not my home. I'm just passing through.

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    next step

    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:
    1. Dim i As Integer = 3000
    2.         Dim str As String = Convert.ToString(i, 2)
    3.         Debug.WriteLine(str)
    4.  
    5.         Dim find As Integer
    6.         For find = Len(str) To 1 Step -1
    7.             If Mid(str, find, 1) = "1" Then
    8.                 Debug.WriteLine("Bit " & Len(str) - find + 1 & " is set.")
    9.             End If
    10.         Next
    This world is not my home. I'm just passing through.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You should look into the BitVector32 class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width