VB.NET Bitwise comparison

kwiksand

New member
Joined
Jun 26, 2006
Messages
3
Programming Experience
5-10
Hi Guys,
I've got one string "1101110111111101110111" of bit codes representing preferences for a fuel card (first character Petrol, second Gas, third Diesel etc), then I'm trying to find the best match in a list of codes from the supplier.
I'm trying to do a bitwise Eqv test for each string comparison to find the closest match i.e
VB.NET:
    1101110111111101110111
    1111110111111101111111
----------------------------
    1101110111111101110111 (Match - with extra options, this is ok)
    1101110111111101110111
    0001110111111101110000
----------------------------
    0001110111111101110000 (No Match)
I'm just not sure how to do the comparison though, how do I convert my bit string to a binary integer to do the comparison on it??
kwik
 
from site:
http://www.vbcity.com/page.asp?f=howto&p=numbers_conv_bin2long

VB.NET:
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'*----------------------------------------------------------*[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'* Name       : convBinToLong                              *[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'*----------------------------------------------------------*[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'* Purpose    : Converts string of Binary bits to Long value*[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'*----------------------------------------------------------*[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'* Parameters : strBin  Required. Binary string to convert. *[/I][/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#008000][I]'*---------------------------------------------------------[/I][/COLOR][/FONT][/COLOR]
 
[COLOR=black][FONT=Courier New][COLOR=#000080]Function[/COLOR] convBinToLong(strBin [COLOR=#000080]As[/COLOR] [COLOR=#000080]String[/COLOR]) [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR] [/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#000080] Dim[/COLOR] lTemp [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR], i [COLOR=#000080]As[/COLOR] [COLOR=#000080]Long[/COLOR]  lTemp = 0  [/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#000080] For[/COLOR] i = [COLOR=#000080]Len[/COLOR](strBin) [COLOR=#000080]To[/COLOR] 1 [COLOR=#000080]Step[/COLOR] -1  [/FONT][/COLOR]
[COLOR=black][FONT=Courier New]   [COLOR=#000080]If[/COLOR] [COLOR=#000080]Mid[/COLOR](strBin, i, 1) = [COLOR=#800080]"1"[/COLOR] [COLOR=#000080]Then[/COLOR]  [/FONT][/COLOR]
[COLOR=black][FONT=Courier New]     lTemp = lTemp + 2 ^ ([COLOR=#000080]Len[/COLOR](strBin) - i) [/FONT][/COLOR]
[COLOR=black][FONT=Courier New]   [COLOR=#000080]End[/COLOR] [COLOR=#000080]If[/COLOR][/FONT][/COLOR]
[COLOR=black][FONT=Courier New] [COLOR=#000080]Next[/COLOR] i  convBinToLong = lTemp[/FONT][/COLOR]
[COLOR=black][FONT=Courier New][COLOR=#000080]End[/COLOR] [COLOR=#000080]Function[/COLOR][/FONT][/COLOR]

Not sure how to take it from here.
 
Back
Top